脚本宝典收集整理的这篇文章主要介绍了php post json参数的传递和接收处理方法,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
$ch = curl_init();
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
'Content-tyPE: application/json; charset=utf-8','Content-Length: ' . strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
//echo $return_content."
";
ob_end_clean();
$return_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
// return array($return_code,$return_content);
return $return_content;
}
$url = "http://127.0.0.1/2.PHP";
$data = json_encode(array('a'=>"weqweqwe",'b'=>2));
//list($return_code,$return_content) = http_post_data($url,$data);
$aaa = http_post_data($url,$data);
//PRint_r($aaa);
echo $aaa;
$ccc=json_decode($aaa);
print_r($ccc);
echo $ccc->b;
echo "";
$JSON = '{"a":1,"b":2,"c":3,"d":4,"e":5}';
var_dump(json_decode($json,true));
?>
以上是脚本宝典为你收集整理的php post json参数的传递和接收处理方法全部内容,希望文章能够帮你解决php post json参数的传递和接收处理方法所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。