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