Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/296.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 经过一些重试后,不可能对url进行卷曲欺骗_Php_Curl_Web Scraping_Http Headers_Spoof - Fatal编程技术网

Php 经过一些重试后,不可能对url进行卷曲欺骗

Php 经过一些重试后,不可能对url进行卷曲欺骗,php,curl,web-scraping,http-headers,spoof,Php,Curl,Web Scraping,Http Headers,Spoof,我用卷曲欺骗刮取重定向结果。在几乎一年毫无问题地得到我想要的东西之后,它突然停止了工作。在浏览器上,它工作得很好,但使用curl,我只能在另一台服务器上得到一个带有404错误的url。我被重定向到错误的url。这是我的密码 function curl_spoofred($url) { $curl = curl_init(); //set some headers if you want $header[] = "Accept: te

我用卷曲欺骗刮取重定向结果。在几乎一年毫无问题地得到我想要的东西之后,它突然停止了工作。在浏览器上,它工作得很好,但使用curl,我只能在另一台服务器上得到一个带有404错误的url。我被重定向到错误的url。这是我的密码

    function curl_spoofred($url) 
{
        $curl = curl_init();

    //set some headers if you want 
        $header[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
        $header[] = "Cache-Control: max-age=0";
        $header[] = "Connection: keep-alive";
        $header[] = "Keep-Alive: 300";
 
        curl_setopt($curl, CURLOPT_URL, $url);
    
    //Spoof the agent
        curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36');

    //Spoof the Referer
        curl_setopt($curl, CURLOPT_REFERER, 'https://wwv.example.com');
        curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);

        curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
        curl_setopt($curl, CURLOPT_COOKIESESSION, true);
        curl_setopt($curl, CURLOPT_FAILONERROR, true);
        curl_setopt($curl, CURLOPT_ENCODING, 'gzip,deflate,br');
        curl_setopt($curl, CURLOPT_AUTOREFERER, true);
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($curl, CURLOPT_TIMEOUT, 10);
        if (!$html = curl_exec($curl))
    { 

    }
return curl_getinfo($curl,CURLINFO_EFFECTIVE_URL );
            curl_close($curl);
}
在Chrome中检查网络控制台后,它给了我以下信息:

Request URL: https://www.example.com/video.php?p=2&c=V1RKa2RHTlRhXbTFhUbmtvMVRWYzRQUT09&id=631
Request Method: GET
Status Code: 301 
Remote Address: 104.26.5.130:443
Referrer Policy: no-referrer-when-downgrade
cache-control: max-age=3600
cf-ray: 51b45707fb1969aa-CDG
date: Tue, 24 Sep 2019 11:15:20 GMT
expect-ct: max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"
expires: Tue, 24 Sep 2019 12:15:20 GMT
location: https://www.example.com/video.php?p=2&c=V1RKa2RHTlRhXbTFhUbmtvMVRWYzRQUT09&id=631
server: cloudflare
status: 301
vary: Accept-Encoding
:authority: www.example.com
:method: GET
:path: /video.php?p=2&c=V1RKa2RHTlRhXbTFhUbmtvMVRWYzRQUT09&id=631
:scheme: https
accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3
accept-encoding: gzip, deflate, br
accept-language: fr-FR,fr;q=0.9,en-US;q=0.8,en;q=0.7,ar;q=0.6
cookie: __cfduid=d948bdac17ae9dca8577dffc6dc3509cd1565743125; _ga=GA1.2.1798570479.1565743125; HstCfa2982759=1565743132096; __dtsu=3DD172A73239535D5B772D7602A61C9A; HstCmu2982759=1568475393523; HstCla2982759=1568892578738; HstPn2982759=1; HstPt2982759=96; HstCnv2982759=18; HstCns2982759=34; _gid=GA1.2.1495236200.1569313316; _gat_gtag_UA_138212094_1=1
referer: https://wwv.example.com/some-article.htm
sec-fetch-mode: nested-navigate
sec-fetch-site: same-site
upgrade-insecure-requests: 1
user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36
p: 2
c: V1RKa2RHTlRhXbTFhUbmtvMVRWYzRQUT09
id: 631

我希望你能帮我做这件事。问候。

似乎他们将Cloudflare放在了自己的域上。使用Chrome/Firefox手动执行此操作,并查看inspector的“网络”选项卡中显示的内容。右键单击请求,然后从菜单中选择“复制为卷曲”。尝试通过命令行运行它-它应该可以工作。然后可以调整代码以匹配复制的卷曲。与cloudflare没有关系。我照Tox说的做了,它成功了。谢谢。