我尝试使用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