The following HTML form posts to remote, external server with success, but my slightly more secure cURL post from a PHP script fails. I don't receive any error information via my script, and the remote party has not been able to furnish any, so my question actually boils down to, what the critical difference between the two post requests is.
The winner:
<form name="frm" action="http://wow.aspx" method="post">
<input type="HIDDEN" name="q1" value="charlesmanson">
<input type="HIDDEN" name="q2" value="batman@home.net">
<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>
And the loser:
$curlSession = curl_init('http://nowbitch.aspx');
curl_setopt ($curlSession, CURLOPT_POST, 1);
curl_setopt ($curlSession, CURLOPT_POSTF开发者_JAVA百科IELDS, "q1=$userLogin&q2=$userRecord[email]&q3=$timeStamp&q4=$hash");
curl_setopt ($curlSession, CURLOPT_FOLLOWLOCATION, 1);
curl_exec ($curlSession);
curl_close ($curlSession);
Real parameters have been lost to protect the guilty.
Try this logic, it facilitate the debugging of curl requests. The main is to CURLOPT_RETURNTRANSFER
and curl_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
}
1.) POST to Action: http://wow.aspx: so curl_init('http://wow.aspx');
2.) Use REFERER: curl_setopt($ch, CURLOPT_REFERER, 'http://nowbitch.aspx');
精彩评论