当前位置:网站首页>PHP curl post x-www-form-urlencoded
PHP curl post x-www-form-urlencoded
2022-07-25 11:02:00 【hexiaoniao】
接口在postman里面测试是成功的。但是PHP curl post这个 接口竟然失败

后面想明白了。请求头的原因。这个接口的请求头是x-www-form-urlencoded。所以curl post也要改成这样
if($url == "" || $timeout <= 0){
return false;
}
$post_data = http_build_query($post_data);//重点
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);//不抓取头部信息。只返回数据
curl_setopt($curl, CURLOPT_TIMEOUT, (int)$timeout);//超时设置
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//1表示不返回bool值
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));//重点
curl_setopt($curl, CURLOPT_POSTFIELDS, $post_data);
$data = curl_exec($curl);
if (curl_errno($curl)) {
return curl_error($curl);
}
curl_close($curl);边栏推荐
猜你喜欢

Experimental reproduction of image classification (reasoning only) based on caffe resnet-50 network

brpc源码解析(二)—— brpc收到请求的处理过程

Review in the middle of 2022 | understand the latest progress of pre training model

Teach you how to configure S2E to UDP working mode through MCU

Differences in usage between tostring() and new string()

Talking about Devops monitoring, how does the team choose monitoring tools?

Information management system for typical works of urban sculpture (picture sharing system SSM)

教你如何通过MCU将S2E配置为UDP的工作模式

基于W5500实现的考勤系统

SQL language (4)
随机推荐
How to solve the problem that "w5500 chip cannot connect to the server immediately after power failure and restart in tcp_client mode"
[imx6ull notes] - a preliminary exploration of the underlying driver of the kernel
brpc源码解析(七)—— worker基于ParkingLot的bthread调度
基于Caffe ResNet-50网络实现图片分类(仅推理)的实验复现
brpc源码解析(一)—— rpc服务添加以及服务器启动主要过程
菜单栏+状态栏+工具栏==PYQT5
return 和 finally的执行顺序 ?各位大佬请看过来,
【MySQL 17】安装异常:Could not open file ‘/var/log/mysql/mysqld.log‘ for error logging: Permission denied
OneNET平台控制W5500开发板LED灯
Arrays in JS
Risks in software testing phase
Oil monkey script link
The JSP specification requires that an attribute name is preceded by whitespace
Breadth first traversal (problems related to sequence traversal of graphs and binary trees)
程序员送给女孩子的精美礼物,H5立方体,唯美,精致,高清
微星主板前面板耳机插孔无声音输出问题【已解决】
Small program of vegetable distribution in community
已解决The JSP specification requires that an attribute name is preceded by whitespace
brpc源码解析(三)—— 请求其他服务器以及往socket写数据的机制
JS中的函数