1

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 ???

3
  • That exact code works for me - I get loads of JSON data (578604 bytes according to the returned Content-Length header). You get a few warnings for your code though - try turning on error_reporting(E_ALL); to see if you get some useful info out of it. Commented Feb 6, 2014 at 15:47
  • CURLOPT_GET option doesn't exists (php.net/manual/en/function.curl-setopt.php) Commented Feb 6, 2014 at 15:49
  • thx Nils and hindmost. On my other server it works fine. Dont really understand, but its working there. Thx for your help. Maybe I should have tried there before. Commented Feb 7, 2014 at 8:01

1 Answer 1

1

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);
Sign up to request clarification or add additional context in comments.

1 Comment

Thx Sabuj. I removed them both, and it works like a charm on my other host.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.