php传递json参数示例
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | <? 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)); ?> |
接收json处理示例
1 2 3 4 5 6 | <? $postData = file_get_contents ( 'php://input' ); echo $postData ; $data = json_encode( array ( 'a' => " 234 " , 'b' =>2)); echo $data ; ?> |
帝国CMS教程
织梦cms教程
discuz教程
ecshop教程
phpcms教程
wordpress教程
苹果cms教程
php教程
数据库教程
微信小程序教程
python教程
css教程
js教程
视频教程
电子书
热门推荐- 01 分享几个随机美女图api接口 3672热度
- 02 优学院自动刷课PHP代码 632热度
- 03 php文件限速下载示例代码 619热度
- 04 随机二次元图片API接口源码 530热度
- 05 php一键打包压缩目录文件代码示例 454热度