PHP post JSON parameter transfer and receive processing method

Source: Internet
Author: User
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!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.