rix*_*rix 3 php post curl get libcurl
我正在使用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);
Run Code Online (Sandbox Code Playgroud)
但是涉及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);
这里3告诉curl模块重定向301和302请求.
0,1,2,3是最后一个参数的有效选项.
0 - >不设置任何行为
1 - >仅对301重定向使用相同类型的请求进行重定向.
2 - >仅针对302重定向使用相同类型的请求进行重定向.
3 - >对301和302重定向使用相同类型的请求进行重定向.
请参阅:请求#49571 CURLOPT_POSTREDIR未实现,其中包含一些有用的注释,如设置自定义请求方法:
curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, "POST");
Run Code Online (Sandbox Code Playgroud)