求大神指导, php中 curl模拟post发送json并接收json,post数据不成功,也取不回 财富值29

2016-11-03 02:59发布

代码放在本地做测试,一个简单的登录,但是curl post不过去数据,也取不回这个success

然后curl代码如下:

<?php  header("content-Type: text/html; charset=UTF-8"); $login_url="http://127.0.0.3/35/doLogin.php"; $data = array("username" => "demo", "password" => "demo","is_ajax"=>"1");                                                                     $data_string = json_encode($data); //提交登录表单请求 $ch=curl_init($login_url); curl_setopt($ch,CURLOPT_HEADER,0); curl_setopt($ch,CURLOPT_RETURNTRANSFER,0); curl_setopt($ch,CURLOPT_POST,1); curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string); curl_setopt($ch, CURLOPT_HTTPHEADER, array("X-Requested-With: XMLHttpRequest"));   $data=curl_exec($ch); curl_close($ch);  var_dump(json_decode($data,true));   ?>

访问curl代码打印出来是NULL

6条回答

关于PHP的curl请参看我写的:

一周热门 更多>