Okay, I want to make a HTTP_POST using cURL to a SSL site. I already imported the certificate to my server. This is my code:
$url = "https://www.xxx.xxx";
$post = "";# all data that going to send
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0');
$exe = curl_exec($ch);
$getInfo = curl_getinfo($ch);
if ($exe === false) {
$output = "Error in sending";
if (curl_error($ch)){
$output .= "\n". curl_error($ch);
}
} else if($getInfo['http_code'] != 777){
$output = "No data returned. Error: " . $getInfo['http_code'];
if (curl_error($ch)){
$output .= "\n". curl_error($ch);
}
}
curl_close($ch);
echo $output;
It keep returned "500". Based on w3schools, 500 means Internal Server Error. Is my server having problem? How to solve/troubleshoot this?
Some servers (especially requested with SSL) returns 500 in cases when some parameters of request is set incorrect.
To avoid «500 error» (for example) be sure to:
curl_setopt(CURLOPT_REFERER, 'http://site.com/ref_page');
curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');
$url = "https://www.xxx.xxx";
$post = "";# all data that going to send
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0');
$exe = curl_exec($ch);
$getInfo = curl_getinfo($ch);
if ($exe === false) {
$output = "Error in sending";
if (curl_error($ch)){
$output .= "\n". curl_error($ch);
}
} else if($getInfo['http_code'] != 777){
$output = "No data returned. Error: " . $getInfo['http_code'];//as preline
if (curl_error($ch)){
$output .= "\n". curl_error($ch);
}
}
curl_close($ch);
echo $output;
BTW: Make sure that CURL moduel is installed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With