如何在PHP CURL中从POST切换到GET [英] How to switch from POST to GET in PHP CURL

查看:178
本文介绍了如何在PHP CURL中从POST切换到GET的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已尝试从之前的Post请求切换到Get请求。

I have tried switching from a previous Post request to a Get request. Which assumes its a Get but eventually does a post.

我在PHP中尝试了以下操作:

I tried the following in PHP :

curl_setopt($curl_handle, CURLOPT_POSTFIELDS, null);
curl_setopt($curl_handle, CURLOPT_POST, FALSE);
curl_setopt($curl_handle, CURLOPT_HTTPGET, TRUE);

我失踪了什么?

信息:
我已经有一个设置为执行POST请求的连接。这完成成功,但后来当我尝试重用连接,并切换回使用setopts上面的GET,仍然最终在内部与不完整的POST头做一个POST。问题是它相信它做一个GET,但最终没有content-length参数的POST头,并且连接失败与411错误。

Additional information: I already have a connection that's setup to do a POST request. That completes successfully but later on when I try to reuse the connection and switch back to GET using the setopts above it still ends up doing a POST internally with incomplete POST headers. The problem is it believes its doing a GET but ends up putting a POST header without the content-length parameter and the connection fails witha 411 ERROR.

推荐答案

Solved:问题出在这里:

Solved: The problem lies here:

我通过设置 POST > _CUSTOMREQUEST POST _POST / code>,而 _POST 切换到 _HTTPGET 。服务器假定 _CUSTOMREQUEST 的标题是正确的,并返回一个411。

I set POST via both _CUSTOMREQUEST and _POST and the _CUSTOMREQUEST persisted as POST while _POST switched to _HTTPGET. The Server assumed the header from _CUSTOMREQUEST to be the right one and came back with a 411.

curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'POST');

这篇关于如何在PHP CURL中从POST切换到GET的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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