Please see the code below:
private static async Task<string> GetResponse(string url)
{
using (HttpClient _HttpClient = new HttpClient())
{
using (var request = new HttpRequestMessage(HttpMethod.Get, new Uri(url)))
{
request.Headers.TryAddWithoutValidation("User-Agent", "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:19.0) Gecko/20100101 Firefox/19.0");
request.Headers.TryAddWithoutValidation("Accept", "*/*");
request.Headers.TryAddWithoutValidation("Accept-Encoding", "gzip, deflate, br");
request.Headers.TryAddWithoutValidation("Connection", "keep-alive");
request.Headers.TryAddWithoutValidation("Accept-Charset", "ISO-8859-1");
using (var response = await _HttpClient.SendAsync(request).ConfigureAwait(false))
{
response.EnsureSuccessStatusCode();
return await response.Content.ReadAsStringAsync();
}
}
}
}
The response returned by the method is garbage i.e. invalid characters. I loaded Fiddler to analyse the response to more detail and then the response returned was valid i.e. the response contains valid characters when Fiddler is active and invalid characters when Fiddler is inactive i.e. closed.
Why is Fiddler affecting the encoding of the response? I have spent half an hour or so Googling this and I have looked here: https://forums.asp.net/t/1778112.aspx?Data+returned+from+an+api+call+has+strange+characters
Why is Fiddler affecting the encoding of the response? I get the correct response when I use Postman.