0

Here I have problem in retrieving data from 3rd party API. I am using file_get_contents() function to fetch data form particular URL using PHP. I got output when pass that URL directly in browser But I am getting error in file_get_contents. I have no idea about it. can anyone help me. ?

  $url= "http://************.com/gds/api/availabilities/134/1594/2016-04-24.json?api_key=1223*****";

     //134 -> Origin id
     //1594-> Destination id
     //2016-04-28 -> Date

    $opts = array(
    'http'=>array(
    'method'=>"GET",
    'header'=>"Accept-language: en\r\n" .
    "Cookie: foo=bar\r\n"
    ));

    $context = stream_context_create($opts);


    $availabilty = file_get_contents($url, false, $context);

    echo "<pre>"; print_r($availabilty); exit;

I am getting response like,

{"response":{"code":401,"message":"gzip not passed as header parameters"}}

I have tried 'Curl' too. Both producing same result. Thanks in advance.

Bala Chandar
  • 140
  • 7
  • I think the remote API is trying to return the result ZIPPED, but as you have not passed the param saying you can cope with gzip it has decided it cannot reply. – RiggsFolly Apr 27 '16 at 10:38
  • Or this might help http://stackoverflow.com/questions/8581924/how-can-i-read-gzip-ed-response-from-stackoverflow-api-in-php/8582042#8582042 – RiggsFolly Apr 27 '16 at 10:40

0 Answers0