简单自用封装:在helper文件下新建curl_helper.php, 如果系统存在则命名前需加MY_,autoload中设置自动加载,则可以直接使用:echo send_get($url)
// 使用curl发送请求 function send_get($url) { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); // 返回数据,不直接输出,否则数据会追加一个布尔值 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // https请求不验证证书 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // https请求不验证host $data = curl_exec($ch); curl_close($ch); return $data; }