//封装request curl方法
public function request($url,$https=true,$method='get',$data=null){
//1.初始化url
$ch = curl_init($url);
//2.设置请求参数
//把数据以文件流形式保存,而不是直接输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//支持http和https协议
//https协议 ssl证书
//绕过证书验证
if($https === true){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
}
//支持post请求
if($method === 'post'){
curl_setopt($ch, CURLOPT_POST, true);
//发送的post数据
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
}
//3.发送请求
$content = curl_exec($ch);
//4.关闭请求
curl_close($ch);
return $content;
}
打开App,阅读手记