Home > Backend Development > PHP Tutorial > 设置了CURLOPT_HTTPHEADER,curl无法传递post参数

设置了CURLOPT_HTTPHEADER,curl无法传递post参数

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:52:10
Original
1884 people have browsed it

设置了下面的代码

curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array("Content-type: application/json" ));
Copy after login
Copy after login

post的参数就传递不过去了,去掉这个代码就可以,这里有什么说法么?

回复内容:

设置了下面的代码

curl_setopt($curl_obj, CURLOPT_HTTPHEADER, array("Content-type: application/json" ));
Copy after login
Copy after login

post的参数就传递不过去了,去掉这个代码就可以,这里有什么说法么?

不知道你接收这个请求的是什么方法。如果是用全局变量 $_POST 那么肯定是不行的。
因为,你这里的Content-type 是 application/json ,服务端不会把他当做一个表单请求,也就不会去解析他。
$_POST 中的值是通过识别请求的header中的Content-type,是form-data才会去解析body中的数据,然后放到$_POST里。
还有,你为什么要指定这个Content-type?不妨换个方法。

我也遇到同样的问题,请问怎么解决的?谢谢啊

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
curl simulated login
From 1970-01-01 08:00:00
0
0
0
Convert cURL command line to PHP cURL code
From 1970-01-01 08:00:00
0
0
0
Convert command line cURL to PHP cURL
From 1970-01-01 08:00:00
0
0
0
How to set boolean value true in php curl
From 1970-01-01 08:00:00
0
0
0
Please tell me, php curl request page shows blank
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template