user3280178
user3280178

Reputation: 21

php cURL request using modified headers

I want to capture the response of a site (http://gnocchi-www.buffalo-ggn.net/bingo2-v2.47.0-JACKET/js/cache/static_desktop_data.json) in my php file to write the available collection items in a databse.

If I enter the adress in my browser, I get a json string as response. But If I use a cURL request, I get an empty response.

Here is my curl code:

$url = 'http://gnocchi-www.buffalo-ggn.net/bingo2-v2.47.0-JACKET/js/cache/static_desktop_data.json';
$headers = array( 
        "Content-Type: application/x-www-form-urlencoded", 
        "Host: gnocchi-www.buffalo-ggn.net", 
        "Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4", 
        "Accept-Encoding: gzip,deflate,sdch", 
        "Accept: */*"
    ); 

$ch = curl_init( $url );
curl_setopt( $ch, CURLOPT_GET, true);
curl_setopt( $ch, CURLOPT_HEADER, true);
curl_setopt( $ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt( $ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36");
curl_setopt( $ch, CURLOPT_REFERER, "https://gs1.wac.edgecastcdn.net/805F48/gnocchi/bingo2-v2.47.0-JACKET/assets/Game.swf");
curl_setopt( $ch, CURLOPT_VERBOSE, true);
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true);
$response=curl_exec( $ch );
echo $response;

the headers that are sent when I enter the url in browser are:

Host: gnocchi-www.buffalo-ggn.net

Connection: keep-alive

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/32.0.1700.107 Safari/537.36

Accept-Encoding: gzip,deflate,sdch

Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4

Can anyone help me with this problem ???

Upvotes: 1

Views: 2065

Answers (1)

Sabuj Hassan
Sabuj Hassan

Reputation: 39405

Remove this from your code:

"Accept-Encoding: gzip,deflate,sdch",

If you really want to send any encoding request, then Add this curl option with your code.

curl_setopt( $ch, CURLOPT_ENCODING, "");

Finally, this one doesn't have any effect on the modern version of libcurl. So remove this one.

curl_setopt( $ch, CURLOPT_GET, true);

Upvotes: 1

Related Questions