php curl sends fake request

    public function curlHtml(){
        //防止超时
        set_time_limit(0);


        //要请求的网站的相关参数
        $url = "http://www.w3school.com.cn";
        /*$data = array(
            'id'=>1
        );*/
        //初始化一个cURL会话
        $ch = curl_init();

        //----------------------------------------

        //伪造来源地址,如果不设置,论坛服务器有可能有验证不允许回复 
        curl_setopt($ch,CURLOPT_REFERER,"http://www.w3school.com.cn");
        //能保存cookie
        curl_setopt($ch,CURLOPT_COOKIESESSION,true);  
         //伪造用户浏览器
        curl_setopt($ch,CURLOPT_USERAGENT,"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36");
        //伪造请求IP,可以为要请求的网站ip
        curl_setopt($ch, CURLOPT_PROXY, 'https://120.55.40.41:80');      
        //CURLOPT_RETURNTRANSFER 为true,它就将使用PHP curl获取页面内容或提交数据,作为变量储存,而不是直接输出。
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);    

        //------------------------------------------

        //使用post方式请求
        /*curl_setopt($ch, CURLOPT_POST, 1);
        //用来支持cookie
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data);*/

        //--------------------------------------------

        //设置要请求的url
        curl_setopt($ch, CURLOPT_URL,$url);
        //执行请求并获取放回数据  
        $res = curl_exec($ch);

        return $res;


    }

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325766738&siteId=291194637