后端开发|php教程
php,curl,json,post
后端开发-php教程
具体描述:
本地模拟请求服务器数据,请求数据格式为json,服务器返回数据也是json。
使用ajax模拟都成功了
彩虹授权系统源码,Ubuntu不能装在ssd,tomcat数据源源配置,网页爬虫设置,php查看指定网页源码,田野 seolzw
$.ajax({type: “POST”,crossDomain: true,url: ‘http://*******’,data: {‘command’:’test’},success: function(e) { console.log(e);//这里log的是json},dataType: ‘json’ });
自适应网店源码,ubuntu需要的软件,汤不热爬虫工具,php 多层elseif,安阳培训seolzw
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打印出来是空的
马甲生成器源码,ubuntu内核签名,下载tomcat怎么解压啊,定向web爬虫,写简单php代码,seo关键词优化seolzw
回复内容:
具体描述:
本地模拟请求服务器数据,请求数据格式为json,服务器返回数据也是json。
使用ajax模拟都成功了
$.ajax({type: “POST”,crossDomain: true,url: ‘http://*******’,data: {‘command’:’test’},success: function(e) { console.log(e);//这里log的是json},dataType: ‘json’ });
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换成数组,最后获取数据也是空