2010-03-16 132 views
2

好的,我想使用cURL将HTTP_POST作为SSL站点。我已经将证书导入到我的服务器。这是我的代码:cURL + HTTP_POST,不断收到500错误。不知道?

$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; 

它保持返回“500”。基于w3schools,500意味着内部服务器错误。我的服务器有问题吗?如何解决/解决这个问题?

回答

0

您的服务器或脚本在服务器上执行的脚本中可能存在未处理的异常。

您应该检查服务器的访问和错误日​​志。

+0

您的意思是,我应该联系我的托管公司? – mysqllearner 2010-03-16 09:35:40

+0

如果你没有直接访问服务器的日志,你可以要求他们发送给你,是的。 – Kaltezar 2010-03-16 11:14:07

1
$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: 请确保已安装CURL模块。

+0

对不起。一些错字错误。我正在编辑代码。我检查了代码,变量名称是正确的,它仍然给我“错误:500”。任何想法? (我会编辑我的问题,以避免,混淆,谢谢) – mysqllearner 2010-03-16 09:43:44

+0

我在我的测试中,只是工作fine.200。 – Young 2010-03-16 09:47:01

+0

那可能会出现服务器问题吗? 500是什么意思?我仍然无法通过,保持返回500. Argggghhh !!!! – mysqllearner 2010-03-16 09:48:38

6

某些服务器(特别是SSL请求)在请求的某些参数设置不正确的情况下返回500。

为了避免«500错误»(例如)须确认:

  • 设置适当的 “的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)');