Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/292.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 无法使用Curl下载URL_Php_Curl - Fatal编程技术网

Php 无法使用Curl下载URL

Php 无法使用Curl下载URL,php,curl,Php,Curl,我正在尝试下载一个URL:使用以下代码。但我得到的回报是状态码为0。但是当从访问它时:它显示301重定向。对于301重定向URL,我的代码似乎也能正常工作 可能是什么问题? <?php print disavow_download_url("http://es.extpdf.com/nagore-pdf.html"); function disavow_download_url($url) { $custom_headers = array(); $custom_h

我正在尝试下载一个URL:使用以下代码。但我得到的回报是状态码为0。但是当从访问它时:它显示301重定向。对于301重定向URL,我的代码似乎也能正常工作

可能是什么问题?

<?php


print disavow_download_url("http://es.extpdf.com/nagore-pdf.html");

function disavow_download_url($url) {

    $custom_headers = array();
    $custom_headers[] = "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
    $custom_headers[] = "Pragma: no-cache";
    $custom_headers[] = "Cache-Control: no-cache";
    $custom_headers[] = "Accept-Language: en-us;q=0.7,en;q=0.3";
    $custom_headers[] = "Accept-Charset: utf-8,windows-1251;q=0.7,*;q=0.7";

    $ch = curl_init();
    $useragent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1";
    curl_setopt($ch, CURLOPT_USERAGENT, $useragent); // set user agent
    curl_setopt($ch, CURLOPT_URL, $url);

    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
    //curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $custom_headers);

    //these two from https
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);


    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 15);
    curl_setopt($ch, CURLOPT_TIMEOUT, 10); //timeout in seconds

    $txResult = curl_exec($ch);

    $statuscode = curl_getinfo($ch, CURLINFO_HTTP_CODE);

    print "statuscode=$statuscode\n";

    print "result=$txResult\n";


}

可以从美国访问url,而不是从您所在的地区。它适用于web嗅探器,因为他们的服务器托管在美国(或extpdf允许的某个地区)

我使用了一个带有curl的USA代理,它返回了我的数据

curl_setopt($ch, CURLOPT_PROXY, "100.9.90.1:3128"); // change IP, Port

链接无效。我无法从浏览器浏览它!请访问它从:然后它显示301 movedas现在似乎他们已经放弃了地理限制。我可以使用位于德国的,返回“HTTP/1.1200ok”的。