我正在尝试使用PHP cURL将一些数据发布到一个本地站点,该站点使用虚拟主机来拥有自定义域http://example.local,但结果似乎是一个Moved Permanently。我怎么才能让它工作呢?
这是我当前的代码:
$url = "http://example.local/paypal_ipn.php"
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, substr_count($req,'&')+1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $req);
//execute post
$result = curl_exec($ch);
//close connection
curl_close($ch);我尝试将CURLOPT_FOLLOWLOCATION设置为true,但没有POST数据。
发布于 2014-03-10 18:28:26
使用CURLOPT_CUSTOMREQUEST代替CURLOPT_POST like;
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");还有一件事,你需要添加
curl_setopt($curl, CURLOPT_POSTREDIR, 3);3表示follow redirect with the same type of request both for 301 and 302 redirects.
通过这样做,第二个请求也将作为POST请求。请注意,在PHP5.3.2 here中实现的CURLOPT_POSTREDIR
发布于 2014-03-10 18:37:27
试试看
//** add options **//
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POSTFIELDS, "your_var");
curl_setopt($curl, CURLOPT_POSTREDIR, 3);
curl_exec($curl);https://stackoverflow.com/questions/22296828
复制相似问题