接收json问题
刚刚学会curl提交json,
但是接收接口返回的数据不会了,会员提交登陆信息后,接口会返回数据,如果返回00就成功,返回11就是登陆失败。
成功记录登陆信息,然后跳转到其它网站。搞一下午都失败。请高手给我例子
万分感谢
分享到: 更多
------解决方案--------------------
提交的服务器端:
if(登录成功){
echo('00');
}else{//失败
echo('11');
}
你这边的程序:
$ch = curl_init();
$url=提交服务服务器地址和参数;
curl_setopt($ch, curlopt_url,$url);
curl_setopt($ch, curlopt_returntransfer,1);
$a=curl_exec($ch);
curl_close($ch);
if($a=='00'){
成功了执行的代码;
}elseif($a=='11'){
登录失败
}
大体这样吧,不知道是不是你想的那样.
------解决方案--------------------
$arraydata = array(name => hagrid, age => 36);
$sendjsondata = json_encode($arraydata);
$ch = curl_init('http://127.0.0.1/jietu/test.php');
curl_setopt($ch, curlopt_customrequest, post);
curl_setopt($ch, curlopt_postfields, $sendjsondata);
curl_setopt($ch, curlopt_returntransfer, true);
curl_setopt($ch, curlopt_httpheader, array(
'content-type: application/json',
'content-length: ' . strlen($sendjsondata))
);
$ret = curl_exec($ch);
if($ret == '00'){
成功了执行的代码;
}elseif($ret == '11'){
登录失败
}
------解决方案--------------------
json_decode