Interface development attention to the problem of the transfer parameter

Source: Internet
Author: User

1Interface Development Note the issue of the transfer of parameters:2 3When the curl () function in PHP makes a POST request, the format of the data can be passed in the following ways:4 5(1): A string of Key=>value key-value pairs that are stitched together by a parameter. The shape is as follows: name=xxx&age=23$sex=16 7This request parameter is defaulted by application/x-www-form-the urlencoded is encoded. 8 9(2): An array of Key=>value key values consisting of parameters (only one-dimensional arrays,an array of higher dimensions will be an error). Ten  Oneform in the following format: A[name= "xxx", age = all, sex =Male] -There are two ways to handle this: -1. Process the multidimensional array http_build_query () until a key=>a string of value key-value pair format.  the      $data= [ -"MSG" = "This is a test data", -"XXX" = "yyyy", -"Msg_data" = [ +"Name" = "Sui", -"Age" =>99, +"Sex" = "male", A"Content" =[ atThe -                                         ] -], -                ]; -           $str=Http_build_query($data); -This method is also encoded by application/x-www-form-urlencoded, where the receiver can$_post Direct Access.  in2. Convert a multidimensional array to a JSON-formatted string, encode the string in Application/json format, and at the receiver through file_get_contents ("PHP://input ") or $globals[' http_raw_post_data '] to get the JSON-formatted string passed in, and then convert the JSON-formatted string to an array for processing.  -         $data= []; to         $data _string= Json_encode ($data); +..... -         //Set Header information thecurl_setopt ($ch, Curlopt_httpheader,Array( *' Content-type:application/json ', $' Content-length: '.strlen($data _string))Panax Notoginseng               ); -Note: For data encoded in Application/json format,$_post is not directly accessible., you need to pass file_get_contents ("PHP://input ") or $globals[' Http_raw_post_data '].  the  

Interface development attention to the problem of the transfer parameter

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.