微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php post json参数的传递和接收处理方法

页面1 ,PHP传递json参数的页面

1.PHP

rush:xhtml;"> $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));
 
?>

页面2,参数接收处理:

2.PHP

rush:xhtml;"> " 234 ",'b'=>2)); echo $data; ?>

以上这篇PHP post json参数的传递和接收处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持编程之家。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐