curl的Get请求,封装方法

//GET请求
//参数1是请求的url
//参数2是发送的数据的数组
//参数3是其他GET选项
private function curlGET($url, array $get = array(), array $options = array())
{
$defaults = array(
CURLOPT_URL => $url . (strpos($url, '?') === FALSE ? '?' : '') . http_build_query($get),
CURLOPT_HEADER => 0,
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_TIMEOUT => 15,
CURLOPT_SSLVERSION => 1,
CURLOPT_SSL_VERIFYPEER => 0,
CURLOPT_SSL_VERIFYHOST => 2
);

$ch = curl_init();
curl_setopt_array($ch, ($options + $defaults));

$result = curl_exec($ch);
if ($result === false)
{
Yii::log("GET ERROR:" . curl_error($ch));
}

curl_close($ch);

return $result;
}
posted @ 2018-10-30 14:59  gram5988  阅读(690)  评论(0编辑  收藏  举报