本地模拟请求服务器数据,请求数据格式为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换成数组,最后获取数据也是空
