CURL + HTTP_POST, get 500 errors. I do not know?

Ok, I want to do HTTP_POST using cURL for the SSL site. I have 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 returns "500". Based on w3schools, 500 stands for Internal Server Error. Am I having a server problem? How to solve / fix this problem?

+3
source share
3 answers

Some servers (especially those requested using SSL) return 500 when some of the request parameters are set incorrectly.

To avoid " 500 errors " (for example), follow these steps:

  • "Referer:", ,

curl_setopt(CURLOPT_REFERER, 'http://site.com/ref_page');

  • "User-Agent:",

curl_setopt(CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)');

+6
$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: , CURL .

+1

You have something wrong inside your server or script running on the server that may cause an unhandled exception.

You must check server access and error logs.

0
source

Source: https://habr.com/ru/post/1737117/


All Articles