Reputation: 89
Please need your help!
I send a post using cURL but the response is blank (boolean false). If I post the data on browser like just pressing the https://www.example.com/myaccount/transfer.php?username=usernamer&password=pass&deposit=5
the browser shows the following result:
1 0 success Your account has been deposited
.
When I see the browser source code the results are:
<?xml version="1.0" encoding="utf-8"?>
<TransferResponse>
<version>1</version>
<result>0</result>
<resultstring>success</resultstring>
<description>Your account has been deposited</description>
</TransferResponse>
Let me attach the my cURL code:
<?php
$config = array
(
"url" => "https://www.example.com/myaccount/",
"transfer" => "transfer.php",
"browser" => "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.16 (KHTML, like Gecko) Chrome/10.0.648.204 Safari/534.16"
);
$postFields = "username=username&password=pass&deposit=5";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $config['url'] . $config['transfer']);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_CAINFO, getcwd() . "/cert/GeoTrustGlobalCA.crt");
curl_setopt($ch, CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postFields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $config['browser']);
curl_setopt($ch, CURLOPT_REFERER, $config['url']);
curl_setopt($ch, CURLOPT_HEADER, true);
$content = curl_exec($ch);
var_dump($content);
var_dump(curl_getinfo($ch));
curl_error($ch);
curl_close($ch);
echo $content;
?>
Please, assist me to get the result in cURL. I have tried many ways. I have surfed internet for 2 days straight. At last I decided to ask here. Can someone figure out what the problem is? The followings are done:
http
(not https) as xml.https
(not http) follows:
Failed: Error Number: 60. Reason: SSL certificate problem, verify that the CA cert is OK. Details:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failedhttp
(not https) just redirects warning page of www.example.comvar_dump($content); and var_dump(curl_getinfo($ch));
results are:
boolean false array (size=26) 'url' => string 'https://www.example.com/myaccount/transfer.php' (length=46) 'content_type' => null 'http_code' => int 0 'header_size' => int 0 'request_size' => int 0 'filetime' => int -1 'ssl_verify_result' => int 0 'redirect_count' => int 0 'total_time' => float 1.451 'namelookup_time' => float 0 'connect_time' => float 0 'pretransfer_time' => float 0 'size_upload' => float 0 'size_download' => float 0 'speed_download' => float 0 'speed_upload' => float 0 'download_content_length' => float -1 'upload_content_length' => float -1 'starttransfer_time' => float 0 'redirect_time' => float 0 'certinfo' => array (size=0) empty 'primary_ip' => string '177.70.43.10' (length=11) 'primary_port' => int 443 'local_ip' => string '192.168.11.9' (length=0) 'local_port' => int 0 'redirect_url' => string '' (length=0)
Upvotes: 1
Views: 6620
Reputation: 3225
Setting SSL verification to false defeats the purpose of SSL. A proper solution is to set the CA certs for CURL.
Solution 1 (Changes to PHP.ini):
Set the curl.ca_info options to point to the location of the cacert.pem
Example: curl.ca_info="C:\xampp\cacert.pem"
Restart Apache
Solution 2 (Set options before each CURL call)
Write the following code:
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt ($ch, CURLOPT_CAINFO, "pathto\cacert.pem");
Source: http://tumblr.wehavefaces.net/post/52114563111/environment-windows-xampp-curl-library
Upvotes: 1
Reputation: 449435
If this
SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed
is your problem, the curl_setopt()
setting
CURLOPT_SSL_VERIFYPEER
might be for you:
FALSE to stop cURL from verifying the peer's certificate. Alternate certificates to verify against can be specified with the CURLOPT_CAINFO option or a certificate directory can be specified with the CURLOPT_CAPATH option.
So set
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
and probably also
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
Upvotes: 1