页面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."<br>"; 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 "<hr>"; $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参数的传递和接收处理方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持移动技术网。
如对本文有疑问, 点击进行留言回复!!
如何去设计前端框架能力?星巴克消息开放项目从0到1,从点到面的思考
PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分
网友评论