views:

35

answers:

1

I am trying to use the SO API (eg: http://api.stackoverflow.com/1.0/users/3) to get some data:

<?php

$data = file_get_contents('http://api.stackoverflow.com/1.0/users/3');
echo $data;

?>

But the returned contents are garbled. I tested it on a couple different servers, including http://codepad.viper-7.com/9GFvsM. Is it my code or the API?

+2  A: 

The response is gzipped. I recommend you use curl and set CURLOPT_ENCODING to gzip.

Matthew Flaschen
Figured this out just now.
Rogue
It shouldn't be gzipped if the client didn't request it as such, should it?
Pekka
@Pekka See http://stackapps.com/questions/729/server-has-stopped-obeying-accept-encoding-header
Artefacto
@Artefacto cheers. I agree with `Then the server should send a 406 response`.
Pekka