revo
revo

Reputation: 48751

cURL doesn't fetch content

I use cURL to fetch a page content from 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; 

But the output is:

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] => 
)

And without urlencode or with file_get_contents it echoes 400 Bad Request error.

Any help is appreciated.

Update

When comment out the commented line this error is given:

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

Without urlencode output is:

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>

Upvotes: 0

Views: 1058

Answers (1)

Jake N
Jake N

Reputation: 10583

Your URL redirects from

http://filestube.com/93TtL7UrDSvedJF7rSR1sE

to

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

Try it with the www.

Or set this to true by un-commenting it

CURLOPT_FOLLOWLOCATION => true,  

Upvotes: 3

Related Questions