Dealing with compressed JSON string from external API I'm trying to call the Stack Exchange API but it sends compressed JSON strings and I can't uncompress it.

$request = drupal_http_request('https://api.stackexchange.com/2.2/users?order=desc&amp;sort=reputation&amp;site=stackoverflow');
$uncompressed = gzinflate($request-&gt;data);
$json_response = drupal_json_decode($uncompressed);


I'm getting an error like this: Warning: gzinflate(): data error in adventure_profile_profile() (line 104 of /home/justine/www/adventure/sites/all/modules/custom/adventure_profile.module). (where line 104 is $uncompressed = gzinflate($request-&gt;data);).

Am I doing something wrong?
Ok, I'm sorry I just figure it out. I wasn't looking at the $request-&gt;headers to see what method to uncompress I have to use. Here is the solution:

$request = drupal_http_request('https://api.stackexchange.com/2.2/users?order=desc&amp;sort=reputation&amp;site=stackoverflow');

if (isset($request-&gt;headers['content-encoding'])) {
  if ($request-&gt;headers['content-encoding'] == 'gzip') {
    $request-&gt;data = gzinflate(substr($request-&gt;data, 10));
  }
  elseif ($request-&gt;headers['content-encoding'] == 'deflate') {
    $request-&gt;data = gzinflate($request-&gt;data);
  }
}

$json_response = drupal_json_decode($request-&gt;data);