$url:请求地址
$param:请求参数,JSON字符串格式,即数组通过json_encode获得
function httpRequest ($url, $param)
{
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, FALSE);
curl_setopt($curl, CURLOPT_TIMEOUT, 1000);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); // 重点
curl_setopt($curl, CURLOPT_POSTFIELDS, $param);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // 不进行SSL验证
$response = curl_exec($curl);
if (curl_error($curl)) {
return curl_error($curl);
}
curl_close($curl);
return $response;
}