2011-04-28 25 views
0

下面的HTML表單發佈到遠程,外部服務器成功,但是我的PHP腳本稍微更安全的cURL帖子失敗。我沒有通過我的腳本收到任何錯誤信息,遠程方也無法提供任何信息,所以我的問題實際上歸結爲兩個帖子請求之間的關鍵區別。PHP中的這個cURL文章與直接的HTML文章有什麼不對?

贏家:

<form name="frm" action="http://wow.aspx" method="post"> 
<input type="HIDDEN" name="q1" value="charlesmanson"> 
<input type="HIDDEN" name="q2" value="[email protected]"> 
<input type="HIDDEN" name="q3" value="20110428092741"> 
<input type="HIDDEN" name="q4" value="6E1AAB44-7508-4BF4-ADA8-0535E880A996"> 
<input type="submit" value="Go for it!" /> 
</form> 

而失敗者:

$curlSession = curl_init('http://nowbitch.aspx'); 
curl_setopt ($curlSession, CURLOPT_POST, 1); 
curl_setopt ($curlSession, CURLOPT_POSTFIELDS, "q1=$userLogin&q2=$userRecord[email]&q3=$timeStamp&q4=$hash"); 
curl_setopt ($curlSession, CURLOPT_FOLLOWLOCATION, 1); 
curl_exec ($curlSession); 
curl_close ($curlSession); 

真實參數已經失去了保護有罪。

+0

您必須添加一個最後的斜槓的URL。 curl_init('http://nowbitch.aspx');'=>'curl_init('http://nowbitch.aspx/');' – Christian 2011-04-28 20:38:27

+2

嘗試使用像Wireshark或Fiddler2這樣的工具來攔截正在生成的實際HTTP請求當你提交表格時。確保你複製了所有的頭文件,並且'curl_init()'的值並不是一個有效的URL。 – Dereleased 2011-04-28 20:39:07

+0

可能重複的[cURL不返回任何東西?](http://stackoverflow.com/questions/5797112/curl-not-returning-anything) – Christian 2011-04-28 20:39:12

回答

0

試試這個邏輯,它便於調試curl請求。主要是CURLOPT_RETURNTRANSFERcurl_getinfo

$ch = curl_init(); 
... 

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

$result = curl_exec($ch); 
$info = curl_getinfo($ch); 

if ($result === false || $info['http_code'] != 200) { 
    // ERROR 
} else { 
    // OK 
} 
0

1)POST到行動:http://wow.aspx:所以curl_init('http://wow.aspx');

2)使用REFERER:curl_setopt($ch, CURLOPT_REFERER, 'http://nowbitch.aspx');