views:

241

answers:

3

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?

A: 

You have something wrong inside your server or the script executed on the server which, maybe, throw an unhandled exception.

You should check the server's access and error logs.

Kaltezar
Do you mean, I should contact my hosting company?
mysqllearner
If you don't have direct access to server's logs, you may ask them to send them to you, yes.
Kaltezar
A: 
$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($geInfo['http_code'] != 777){        //here $geInfo should be $getInfo
$output = "No data returned. Error: " . $geInfo['http_code'];//as preline
if (curl_error($ch)){
    $output .= "\n". curl_error($ch);
}
}

curl_close($c);  //$c should be $ch

echo $output;

BTW: Make sure that CURL moduel is installed.

SpawnCxy
Sorry. Some typo mistakes. I was editing the code. I checked the code, the variable name is correct, it still gives me "Error: 500". Any idea? (i will edit my question, to avoid, confusion, thanks)
mysqllearner
I tested it in my wamp,just works fine.200 is got.
SpawnCxy
Then could it be, server problems? What is that 500 means? I still cant get through, keep return 500. Argggghhh!!!!
mysqllearner
probably CURL moduel hasn't been installed yet in your server.
SpawnCxy
Hi SpawnCxy, the cURL module is installed. I was able to send to non-SSL site, using similar codes. Not sure if its about the SSL thingy
mysqllearner
I tried "h-t-tps://gmail.com" as $url,got 301
SpawnCxy
A: 

is your problem resolved? please let me know. I am facing the same problem!!!

jtanmay