cURL post not working PHP

前端 未结 5 1276
感情败类
感情败类 2021-01-01 00:11

I\'m having trouble using cURL for a specific page.

A live code working: http://svgen.com/jupiter.php

Here is my code:

    $url = \'https://u         


        
相关标签:
5条回答
  • 2021-01-01 00:55
    $data = array('codpes' => 'someLogin', 'senusu' => 'somePass', 'Submit' => '1');
    

    should have been

    $data = http_build_query(array('codpes' => 'someLogin', 'senusu' => 'somePass', 'Submit' => '1'));
    

    It automatically url encodes your query string as well and is safer than manual methods..

    0 讨论(0)
  • 2021-01-01 00:56

    Try these:

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
    curl_setopt($ch, CURLOPT_CAINFO, '/etc/pki/tls/cert.pem'); // path is valid for RHEL/CentOS
    

    This makes sure the resource you're "curling" has a valid SSL certificate. It is not recommended to set "CURLOPT_SSL_VERIFYPEER" to false (0).

    0 讨论(0)
  • 2021-01-01 00:56

    You're on a secure connection, why are you using :

    curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP);
    

    Use instead :

    curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);
    
    0 讨论(0)
  • 2021-01-01 00:57

    make your post data as:

    $data = array('codpes' => 'someLogin', 'senusu' => 'somePass', 'Submit' => '1');
    $postData = "";
    foreach( $data as $key => $val ) {
       $postData .=$key."=".$val."&";
    }
    $postData = rtrim($postData, "&");
    

    and change:

    curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
    

    to

    curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
    
    0 讨论(0)
  • 2021-01-01 01:04

    Most probably it is the SSL verification problem.

    Add

    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    

    Also if you use CURLOPT_PROTOCOLS option, it should be HTTPS since you are posting to a secure url

    curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS);    // you currently have http
    
    0 讨论(0)
提交回复
热议问题