2010-03-16 131 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)');