0

我使用 cURL 从以下位置获取页面内容filestube.com

    $link = "http://filestube.com/93TtL7UrDSvedJF7rSR1sE";
    $options = array(  
      CURLOPT_RETURNTRANSFER => true,  
      CURLOPT_HEADER         => false,  
     // CURLOPT_FOLLOWLOCATION => true,  
      CURLOPT_ENCODING       => "",  
      CURLOPT_USERAGENT      => "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)",  
      CURLOPT_AUTOREFERER    => true,  
      CURLOPT_CONNECTTIMEOUT => 120,    
      CURLOPT_TIMEOUT        => 120,  
      CURLOPT_MAXREDIRS      => 10,
    );  

    $ch = curl_init(urlencode($link));  
    curl_setopt_array($ch, $options);  
    $content = curl_exec($ch);  
    $header = curl_getinfo($ch);  
    curl_close($ch);  
    print_r($header);  
    echo $content; 

但输出是:

Array
(
    [url] => HTTP://http%3A%2F%2Ffilestube.com%2F93TtL7UrDSvedJF7rSR1sE%3Cbr+%2F%3E
    [content_type] => 
    [http_code] => 0
    [header_size] => 0
    [request_size] => 0
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0
    [namelookup_time] => 0
    [connect_time] => 0
    [pretransfer_time] => 0
    [size_upload] => 0
    [size_download] => 0
    [speed_download] => 0
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => -1
    [starttransfer_time] => 0
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [redirect_url] => 
)

没有urlencode或有file_get_contents它会产生400 Bad Request错误。

任何帮助表示赞赏。

更新

当注释掉注释行时,会出现此错误:

Warning: curl_setopt_array() [function.curl-setopt-array]: CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set

没有urlencode输出是:

Array
(
    [url] => http://www.filestube.com/93TtL7UrDSvedJF7rSR1sE<br />
    [content_type] => text/html
    [http_code] => 400
    [header_size] => 97
    [request_size] => 181
    [filetime] => -1
    [ssl_verify_result] => 0
    [redirect_count] => 0
    [total_time] => 0.027514
    [namelookup_time] => 0.000785
    [connect_time] => 0.01413
    [pretransfer_time] => 0.014176
    [size_upload] => 0
    [size_download] => 90
    [speed_download] => 3271
    [speed_upload] => 0
    [download_content_length] => -1
    [upload_content_length] => 0
    [starttransfer_time] => 0.027489
    [redirect_time] => 0
    [certinfo] => Array
        (
        )

    [redirect_url] => 
)
<html><body><h1>400 Bad request</h1>
Your browser sent an invalid request.
</body></html>
4

1 回答 1

3

您的网址重定向自

http://filestube.com/93TtL7UrDSvedJF7rSR1sE

http://www.filestube.com/93TtL7UrDSvedJF7rSR1sE

用 www 试试。

或者通过取消注释将其设置为 true

CURLOPT_FOLLOWLOCATION => true,  
于 2013-08-01T16:47:53.420 回答