//$date是个字符串!字符串!字符串!传进来的时候需要将$data用json_encode转为字符串
function curl_post($url, $data)
{
$ch = curl_init();
$timeout = 300;
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
//最重要的就是下面这个httpheader,如果不加这个header会提示报错
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-AjaxPro-Method:ShowList',
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($data))
);
$handles = curl_exec($ch);
curl_close($ch);
return $handles;
}
tip:$date是个字符串!字符串!字符串!传进来的时候需要将$data用json_encode转为字符串