簡體   English   中英

即使設置了標志,PHP cURL也不跟隨重定向

[英]PHP cURL doesn't follow redirects even if the flag is set

即使我設置了curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true) cURL也不想跟隨重定向,它僅顯示“ 301移動的頁面”。 在多個站點嘗試過。 奇怪的是,它可以在localhost上運行,但是當我將其上載到Webspace時,它將拒絕運行。

我的網絡托管服務提供商可能會做出一些無法使用的調整嗎? 從來沒有見過這樣的事情:(

這是代碼:

    $ch=curl_init();
    curl_setopt($ch, CURLOPT_URL, 'http://google.com');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_ENCODING, '');
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36');
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
        'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
        'Accept-Language: en-US,en;q=0.5',
        'Accept-Encoding: gzip, deflate',
        'Connection: keep-alive'
        ));
    $result = curl_exec($ch);
    curl_close($ch);

我有一個類似的問題,這是由於cURL在收到重定向標頭后立即執行了GET 為了解決這個問題,我指定了CURLOPT_CUSTOMREQUEST

例:

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM