我嘗試使用php和curl發佈帖子請求。這裏是我的代碼php + curl無法設置發佈方法
//PHP 5.3.5 and curl: 7.18.2
$ch = curl_init();
if(!empty($save_cookie)){
curl_setopt($ch, CURLOPT_COOKIEJAR, $save_cookie);
curl_setopt($ch, CURLOPT_COOKIEFILE, $save_cookie);
}else{
curl_setopt($ch, CURLOPT_COOKIE, $cookie);
}
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);
curl_setopt($ch, CURLOPT_URL, 'http://localhost/post.php');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $pars);
curl_setopt($ch, CURLOPT_HEADER, $header);
curl_setopt($ch, CURLOPT_NOBODY, !$body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$postResult = curl_exec($ch);
if (curl_errno($ch)) {
return false;
}
curl_close($ch);
return $postResult;
print_r($_SERVER);
捲曲的結果回報總是
[REQUEST_METHOD] => GET
奇怪。你可以發佈數據包跟蹤嗎? (使用Wireshark或類似的。)另外,是通過CGI還是作爲模塊調用PHP?什麼網絡服務器?另見http://redmine.lighttpd.net/issues/1472。我懷疑如果你要設置POST數據並在post.php中查看'$ _POST',你會看到你的數據。 – Brad 2012-02-28 01:17:45
我正在使用apache + fastcgi。我也打印$ _POST,但它'空 – complez 2012-02-28 01:23:29