您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php中curl模拟post发送json并接收json

2024/3/27 19:22:35发布12次查看
具体描述:
本地模拟请求服务器数据,请求数据格式为json,服务器返回数据也是json。
使用ajax模拟都成功了
curl就没有成功
$url = 'http://*******';
$param = {'command':'test'};
$ch = curl_init($url); //请求的url地址
curl_setopt($ch, curlopt_customrequest, post);
curl_setopt($ch, curlopt_postfields, $param);//$data json类型字符串
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_httpheader, array('content-type: application/json', 'content-length: ' . strlen($param)));
$data = curl_exec($ch);//这里的data打印出来是空的
回复内容: 具体描述:
本地模拟请求服务器数据,请求数据格式为json,服务器返回数据也是json。
使用ajax模拟都成功了
curl就没有成功
$url = 'http://*******';
$param = {'command':'test'};
$ch = curl_init($url); //请求的url地址
curl_setopt($ch, curlopt_customrequest, post);
curl_setopt($ch, curlopt_postfields, $param);//$data json类型字符串
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_httpheader, array('content-type: application/json', 'content-length: ' . strlen($param)));
$data = curl_exec($ch);//这里的data打印出来是空的
$param = {'command':'test'};
这一行改成php数组键值的形式。
因为curl模拟post的时候,post的参数应该是以数组的形式传参。
请问lz最后的代码是怎么写的,我把param换成数组,最后获取数据也是空
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product