This article mainly introduces the PHP post JSON parameter transfer and receive processing method, has a certain reference value, now share to everyone, the need for friends can refer to
Page 1, PHP to pass JSON parameters to the page:
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: '. St Rlen ($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 "
Page 2, parameter receive processing:
2.php
<? $postData = file_get_contents (' php://input '); Echo $postData; $data = Json_encode (Array (' a ' = ' = ' 234 ', ' B ' =>2)); echo $data;?>
The above is the whole content of this article, thank you for reading. Read more about topic.alibabacloud.com!