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 The code is as follows:
$data = array(
'name'=>'scofield',
'time'=> '2012-2-3'
)
Next, you need to change $data into a string first
$post_data = http_build_query($data);
Use http_build_query After conversion,
curl_setopt($c, CURLOPT_POSTFIELDS, $post_data);
seems to have no problem. But in actual operation, $post_data is not posted. So, I wrote a conversion method and it was OK.
Copy code The 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 Huang Bin-huangbin for testing http_build_query($data,"","&"); , no need to write your own method to parse it. .
http_build_query A remote attacker could exploit this vulnerability to obtain sensitive memory information. Please use it with caution
http://www.bkjia.com/PHPjc/325209.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/325209.htmlTechArticleWhen we use CURL to post data, we need to set the post data curl_setopt($c, CURLOPT_POSTFIELDS, $post_data ); If $data here is the copy code, the code is as follows: $data = arr...