3

I'm trying to request list of tags on StackExchange in JSON format by url, but problem is, that I'm getting some broken text instead of JSON, so I can't even parse it.

P.S. Done it with the help of RestSharp.

private void Refresh()
    {
        var client = new RestClient("http://api.stackexchange.com/2.2/tags?order=desc&sort=popular&site=stackoverflow");

        var result = client.Execute(new RestRequest(Method.GET));

        var array = JsonConvert.DeserializeObject<Root>(result.Content);

        Platforms = array.Platforms;
    }
  • Please [edit your question](http://stackoverflow.com/posts/29486722/edit) and include the **broken text**. – ekad Apr 07 '15 at 08:07
  • 1
    I don't use c# but I've dabbled with the stackexchange api, and from what I experienced, the response is gzip encoded. With the Java client I used, I had to use a gzip decoder – Paul Samsotha Apr 07 '15 at 08:15
  • Don't deface your question when you found the answer. Please [post an answer with your solution](http://stackoverflow.com/revisions/29486722/3). – CodeCaster Apr 07 '15 at 09:05

2 Answers2

2

If you make GET request to this URL using Fiddler, you will see that response has a header:

Content-Encoding: gzip

Which means that response is compressed with gzip. Good news is that HttpWebRequest can handle that:

request.AutomaticDecompression = DecompressionMethods.Deflate | DecompressionMethods.GZip;

After you add this row you will get nice and readable JSON.

Aleksandr Ivanov
  • 2,778
  • 5
  • 27
  • 35
0

As @peeskillet mentions, this looks like compressed data. Please have a look at What is the canonical method for an HTTP client to instruct an HTTP server to disable gzip responses? and especially this answer.

Something like

Accept-Encoding: *;q=0

should help.

Community
  • 1
  • 1
Stephen Reindl
  • 5,659
  • 2
  • 34
  • 38