Python语言技术文档

微信小程序技术文档

php语言技术文档

jsp语言技术文档

asp语言技术文档

C#/.NET语言技术文档

html5/css技术文档

javascript

点击排行

您现在的位置:首页 > 技术文档 > json

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

来源:中文源码网    浏览:340 次    日期:2024-04-23 04:25:51
【下载文档:  php post json参数的传递和接收处理方法.txt 】


php post json参数的传递和接收处理方法
页面1 ,php传递json参数的页面:
1.php
function http_post_data($url, $data_string) {
$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
$postData = file_get_contents('php://input');
echo $postData;
$data = json_encode(array('a'=>" 234 ", 'b'=>2));
echo $data;
?>
以上这篇php post json参数的传递和接收处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持中文源码网。

相关内容