I am running some PHP code to my browser.
If I navigate to a URL like google.com it tells me the document has moved here . . i.e to another google link.
I set cURL follow location to true.
Also. When the query actually goes through it forces my browser to download a webpage in a .gz file.
Please help. I don’t want it to download. I want it to display.
curl_setopt($ch, CURLOPT_URL, trim("http://".trim($host).$q));
curl_setopt($ch, CURLOPT_PORT, intval(trim($port)));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $v);
EDIT ::
Your browser sent a bad request when requesting sites like stackoverflow.com. . even 4shared.com does the same thing.
Here is the HTTPHEADER array I use in cURL;
Array
(
[0] => Proxy-Connection: Close
[1] => Cache-Control: max-age=0
[2] => User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1017.2 Safari/535.19
[3] => Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[4] => Accept-Encoding: gzip,deflate,sdch
[5] => Accept-Language: en-US,en;q=0.8
[6] => Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
[7] => Cookie: __qca=P0-9
[8] => Connection: Close
)
It’s the same curl code I use above.
Host: stackoverflow.com
Q: /questions/tagged/java
For solving the gzip problem: try setting
CURLOPT_ENCODINGto an empty string before settingCURLOPT_HTTPHEADER. The problem is that cURL is not expecting a compressed response (since you haven’t set what encodings it should accept) but manually ask for a compressed response anyway using your custom HTTP headers.