位置:首页 > 网络编程 > php&cms
点击展开栏目简介
php技术和开源cms使用

php:curl content-type 转为 x-www-form-urlencoded 方式的坑

分享到: 微信 新浪微博 更多

 网上转变的方法基本都是写添加下面这句:

curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));

但加上去后却根本没效果。

要想以 x-www-form-urlencoded 方式发送,最关键其实是发送的数据格式。

方式from-data试发送的数据用的是array格式,而方式为 x-www-form-urlencoded 时需要用key=value&key=value的格式发送,发送的是string型的数据。

from-data数据的为:
​​​​​​$data = [
    'name' => 'xiaoming',
    'sex' => 1
];
x-www-form-urlencoded时的数据则要变为
http_build_query($data);

上篇:php:通过php将html字符串或文件当做dom处理(php解析html类库simple_html_dom)

下篇:php:实现(php或shtml)require/include包含文件带参数

发表评论 ​共有​条评论
  • 匿名发表