首页 > 其他分享 >httpcurls

httpcurls

时间:2022-09-20 09:34:06浏览次数:56  
标签:httpcurls ch setopt header curl post CURLOPT

public function httpcurls($url,$data,$is_post=0,$header=null)
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);//初始化curl会话
if (!empty($header)){
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//自动设置访问header信息
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//将获取的信息以字符串返回
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);//禁止进行证书验证 https
if ($is_post == 1){
curl_setopt($ch, CURLOPT_POST, 1);//curl post 访问
}
if (!empty($data)){
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);//post传递的参数值
}
$output = curl_exec($ch);
curl_close($ch);//关闭curl资源 并且释放
return $output;
}

标签:httpcurls,ch,setopt,header,curl,post,CURLOPT
From: https://www.cnblogs.com/ruan1655301753/p/16709935.html

相关文章