curl post

来源:互联网 发布:ug编程优化刀路技巧 编辑:程序博客网 时间:2024/04/30 11:05
public function curlRequest($url,$data,$method){    //初始化    $ch = curl_init();    //请求地址    curl_setopt($ch, CURLOPT_URL, $url);    //请求方式    curl_setopt($ch,CURLOPT_CUSTOMREQUEST,$method);    //ssl认证    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);    //模拟浏览器请求    curl_setopt($ch,CURLOPT_USERAGENT,'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:39.0) Gecko/20100101 Firefox/39.0');    // 自动设置Referer    curl_setopt($ch, CURLOPT_AUTOREFERER, 1);    //判断    if($method=="POST"){        curl_setopt($ch,CURLOPT_POSTFIELDS,$data); //参数    }    //设置返回值是否显示在屏幕上 1 存变量 0显示屏幕上    curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);    //采集    $tempInfo=curl_exec($ch);    //错误    if(curl_errno($ch)){        return curl_error($ch);    }    //关闭    curl_close($ch);    //返回    return $tempInfo;}
1 0
原创粉丝点击