How can I prevent API returning response as gibberish data instead of JSON?

Viewed 50

I am using RapidAPI for integration of https://priceline-com-provider.p.rapidapi.com/v1/hotels/search external API with my asp.net micro-service. I need to get a JSON response from the API however it is returning gibberish data. I have tried many things to no success. enter image description here

To make sure it is good the request, I used Postman to test and it worked out fine.enter image description here

What can I do to solve this?

1 Answers

In my case, the response was Accept-Encoding: deflate/gzip and therefore I had to insert a HttpClientHandler into the HttpClient with the correct settings:

using (var HttpClientHandler = new HttpClientHandler()
{
    AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate
})
{

    using (var client = new HttpClient(HttpClientHandler))
    {
    }
}

Once I did, the await response.Content.ReadAsStringAsync() returned deserializable JSON data.

This answer led me to the solution: https://stackoverflow.com/a/69222690/2504659

Related