微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – Curl:*违反RFC 2616 / 10.3.2并从POST切换到GET

我正在使用curl发布到脚本.

curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$postvars);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,0);

但是涉及301重定向,其中包括从POST切换到GET的卷曲.

HTTP/1.1 301 Moved Permanently
< Location: https://myserver.org/PHP/callback-f.PHP
< Content-Length: 0
< Date: Wed, 16 Nov 2011 17:21:06 GMT
< Server: lighttpd/1.4.28
* Connection #0 to host myserver.org left intact
* Issue another request to this URL: 'https://myserver.org/PHP/callback-f.PHP'
* Violate RFC 2616/10.3.2 and switch from POST to GET
* About to connect() to myserver.org port 443

有谁知道我怎么能阻止卷曲切换到GET请?

解决方法:

可以设置CURLOPT_POSTREDIR来配置此行为(基于卷曲的301位置标头自动重定向的请求方法):

curl_setopt( , CURLOPT_POSTREDIR, 3);

here 3 tells curl module to redirect both 301 as well as 302 requests.

0,1,2,3 are the valid options for the last argument.

0 -> do not set any behavior
1 -> follow redirect with the same type of request only for 301 redirects.
2 -> follow redirect with the same type of request only for 302 redirects.
3 -> follow redirect with the same type of request both for 301 and 302 redirects.

请参阅:Request #49571 CURLOPT_POSTREDIR not implemented有一些有用的注释,比如设置自定义请求方法

curl_setopt( $ch, CURLOPT_CUSTomrEQUEST, "POST"); 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐