Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a request to StackExchange Api [duplicate]

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;
    }
like image 796
Marcus Vertinskiy Avatar asked Mar 03 '26 23:03

Marcus Vertinskiy


1 Answers

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.

like image 195
Aleksandr Ivanov Avatar answered Mar 05 '26 11:03

Aleksandr Ivanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!