简体   繁体   English

PHP 中的 cURL 帖子与直接 HTML 帖子相比有什么问题?

[英]What is wrong with this cURL post in PHP versus a straight HTML post?

The following HTML form posts to remote, external server with success, but my slightly more secure cURL post from a PHP script fails.以下 HTML 表单成功发布到远程外部服务器,但我从 PHP 脚本发布的稍微更安全的 cURL 发布失败。 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_POSTFIELDS, "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.试试这个逻辑,方便调试curl请求。 The main is to CURLOPT_RETURNTRANSFER and curl_getinfo .主要是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
}

1.) POST to Action: http://wow.aspx : so curl_init('http://wow.aspx'); 1.) 发布到操作: http://wow.aspx :所以curl_init('http://wow.aspx');

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM