/**
* 发送HTTP请求方法,目前只支持CURL发送请求
* @param string $url 请求URL
* @param array $data POST的数据,GET请求时该参数无效
* @param array $param GET参数数组
* @param string $method 请求方法GET/POST
* @return array 响应数据
*/
public function https_request($url, $data, $param = '', $method = 'POST')
{
$opts = array(
CURLOPT_TIMEOUT => 4,
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
);
/* 根据请求类型设置特定参数 */
if (!empty($param)) {
$opts[CURLOPT_URL] = $url . '?' . http_build_query($param);
} else {
$opts[CURLOPT_URL] = $url;
}
if (strtoupper($method) == 'POST') {
$opts[CURLOPT_POST] = 1;
$opts[CURLOPT_POSTFIELDS] = $data;
}
/* 初始化并执行curl请求 */
$ch = curl_init();
curl_setopt_array($ch, $opts);
$header = array ();
$header [] = 'Host:www.XXXX.co';
$header [] = 'Connection: keep-alive';
$header [] = 'Accept:text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8';
$header [] = 'Accept-Language: zh-CN,zh;q=0.8';
$header [] = 'Accept-Charset: GBK,utf-8;q=0.7,*;q=0.3';
$header [] = 'Cache-Control:max-age=0';
$header [] = 'Cookie:t_skey=p5gdu1nrke856futitemkld661; t__CkCkey_=29f7d98';
$header [] = 'Content-Type:application/x-www-form-urlencoded';
curl_setopt ( $ch, CURLOPT_HTTPHEADER, $header );
$data = curl_exec($ch);
$error = curl_error($ch);
curl_close($ch);
//发生错误,抛出异常
if ($error) return false;
return $data;
}
11-07
4698
07-26
487