Curl:*违反RFC 2616 / 10.3.2并从POST切换到GET [英] Curl : * Violate RFC 2616/10.3.2 and switch from POST to GET

查看:143
本文介绍了Curl:*违反RFC 2616 / 10.3.2并从POST切换到GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用curl发布到脚本。

I'm using curl to post to a script.

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重定向涉及哪些行为从curl切换到GET。

But there's 301 redirect involved which casues curl to switch from POST to 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

有人知道如何防止curl切换到GET吗?

Does anyone know how I can prevent curl from switching to GET please?

推荐答案

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

CURLOPT_POSTREDIR can be set to configure this behaviour (request method for 301 location header based automatic redirects in curl):


curl_setopt(,CURLOPT_POSTREDIR,3);

curl_setopt( , CURLOPT_POSTREDIR, 3);

这里3告诉curl模块重定向301和302请求。

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

0,1,2,3是最后一个参数的有效选项。

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

0 - >不设置任何行为

1 - >仅对301重定向使用相同类型的请求才能重定向。

2 - >仅对302重定向使用相同类型的请求跟踪重定向。

3 - >对于301和302重定向,使用相同类型的请求跟踪重定向。

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.

另请参阅:请求#49571 CURLOPT_POSTREDIR未实施,其中包含一些有用的注释,例如设置自定义请求方法:

See as well: Request #49571 CURLOPT_POSTREDIR not implemented which has some useful comments, like setting a custom request method:

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

这篇关于Curl:*违反RFC 2616 / 10.3.2并从POST切换到GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆