加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

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

发布时间:2020-12-13 21:44:08 所属栏目:PHP教程 来源:网络整理
导读:我正在使用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,CURLOPT_FOLLOWLOCATION,
我正在使用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,CURLOPT_FOLLOWLOCATION,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");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读