Skip to content
Advertisement

how to decode the Stack Exchange API response

I am trying to retrieve the response of stack exchange api like [http://api.stackexchange.com/2.2/tags?order=desc&sort=popular&site=stackoverflow]

I am using the following code to retrieve the response

JavaScript

But I am getting the response in decoded form as ���n� �߅f]as��DՊ�I��/�m�(��*Ʃ���Kc���

I found the similar question [https://stackoverflow.com/questions/20808901/problems-with-decoding-stack-exchange-api-response] , but I didn’t find any answers for the question.

How to decode the api response?

Thanks in advance.

Advertisement

Answer

The content is compressed. You need to send it through an unzip stream, like

JavaScript

You should also check the content encoding first, and only wrap the stream into a GZIPInputStream if the encoding actually is gzip – some proxies transparently already uncompress the stream.

See SOQuery.java for a complete sample, even though this is using java.net.HttpURLConnection rather than the apache client.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement