4
4

3 回答 3

2

The API Response is GZIP'd. Refer to this page to decoding responses: http://api.stackoverflow.com/1.1/usage/gzip

If you switch to cURL, then you can use the CURLOPT_ENCODING option to decode it.

$url = 'http://api.stackoverflow.com/1.1/users/779187/';
$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL, $url); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
curl_setopt($ch, CURLOPT_ENCODING, 1);
$output = curl_exec($ch); 
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); 
curl_close($ch); 
if($status=='200') {
    $data = json_decode($output);
    echo '<pre>' . print_r($data,true) . '</pre>';
}
于 2012-04-29T11:26:09.050 回答
2

Use gzdecode to decode compressed content. You should use implementation from this page if you don't have gzdecode function. I have checked that it works with the page you want to retrieve.

于 2012-04-29T11:27:35.420 回答
0

Decompress it with gzinflate first.

于 2012-04-29T11:27:28.680 回答