When we use curl to post data, we need to set the post data
curl_setopt ($c, Curlopt_postfields, $post _data);
If the $data here is
Copy Code code as follows:
$data = Array (
' Name ' => ' Scofield ',
' Time ' => ' 2012-2-3 '
)
Next, you need to turn $data into a string
$post _data = Http_build_query ($data);
And the use of http_build_query conversion and then
curl_setopt ($c, Curlopt_postfields, $post _data);
There seems to be no problem. In practice, however, the $post _data was not post. So, I wrote a conversion method after the OK.
Copy Code code 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 Accouts-huangbin's Test http_build_query ($data, "", "&"); You don't have to write your own method to parse it.
Http_build_query remote attackers can exploit vulnerabilities to obtain sensitive memory information. Please use them carefully.