When we use CURL to post data, we need to set post data.
Curl_setopt ($ c, CURLOPT_POSTFIELDS, $ post_data );
Assume that $ data isCopy codeThe Code is as follows: $ data = array (
'Name' => 'scofield ',
'Time' => '2014-2-3'
)
Next, you need to convert $ data into a string.
$ Post_data = http_build_query ($ data );
When http_build_query is used for conversion
Curl_setopt ($ c, CURLOPT_POSTFIELDS, $ post_data );
It seems that there is no problem. However, in actual operations, $ post_data is not post. Therefore, after writing a conversion method, It will be OK.Copy codeThe Code is as follows: function getStr ($ array, $ Separator = '&'){
If (empty ($ array ))
Return;
If (! Is_array ($ array )){
Return $ array;
}
$ ReturnStr = '';
Foreach ($ array as $ key => $ val ){
$ Temp = '';
If (is_array ($ val )){
For ($ I = 0; $ I <count ($ val); $ I ++ ){
$ ReturnStr. = $ key. '['. $ I. ']'. '='. $ val [$ I]. $ Separator;
}
} Else {
$ ReturnStr. = $ key. '='. $ val. $ Separator;
}
}
$ ReturnStr = substr (trim ($ returnStr), 0,-1 );
Return $ returnStr;
}
Thanks to the test http_build_query ($ data, "", "&") of Huang Bin-huangbin kids shoes. You don't need to write your own parsing method.
Http_build_query remote attackers can exploit this vulnerability to obtain sensitive memory information. Please use it with caution