• hifimusic over 4 years ago

    this just started happening and i can't seem to figure out how to display the data properly.

    i am using this code (but same results with cUrl):

    $ctx_options = array('http' => array('method' => 'GET', 'header' => 'Accept-Encoding: gzip, deflate\r\nUser-Agent: someuseragent/0.1 +http://domain.com\r\n'));
    $ctx = stream_context_create($ctx_options);
    echo file_get_contents("http://api.discogs.com/database/search?artist=steve+harley&release_title=&label=&catno=&year=&per_page=50&page=2", false, $ctx);

    data looks like this:
    ‹/Ú)OÿÕ\ëoÛFÿWðµ×2â.ߌƒ_qÒFgÃrzWAÁÈ´Í+E$•Ôú¿ßÌ>øX‰IÑyôCcJ£Ýáü8ïY~:x î£$(¢49øIûtðfÀG!\ØƏ~æpaŠ¿áO ®³?ú,ü<ÅãO³Y𽸍òezŸ¿X¦«ÙmPïƒ<œåa-þdE”Gy~x²8|:ÌÂ8’?Š¨ˆÃ£Ã8xÆG‡Ë HÒ£Ã'øÝÑ¡äêÈ6‘£#rL

    any idea what i can do to get this working again? another user had and solved a similar issue in a java app.

    thanks,
    jason

  • vreon over 4 years ago

    Hi there,

    We recently made the "Accept-Encoding: gzip" header optional -- now you'll only get compressed responses if you ask for it.

    You can either:

    - decompress the stream with a gzip library (the best option), or
    - stop sending the Accept-Encoding header.

    Hope that helps!
  • hifimusic over 4 years ago

    that did help. i removed the accept-encoding, but i could not get it to deflate in PHP. have you successfully deflated it? if so, what function worked?

    just curious and thanks for the snappy repsonse.
  • hifimusic over 4 years ago

    i missed the second part of your post. i am good, thanks again.
  • S8nsick66 over 3 years ago

    Thanks, I also had this problem. Solved it like this:

    $context = stream_context_create($cparams);
    $fp = fopen($url, 'rb', false, $context);
    $meta = stream_get_meta_data($fp);
    $res = gzdecode(stream_get_contents($fp));

    ....

    function gzdecode($data){
    $g=tempnam('/tmp','ff');
    @file_put_contents($g,$data);
    ob_start();
    readgzfile($g);
    $d=ob_get_clean();
    return $d;
    }

Log In You must be logged in to post.