I'm using an HttpClient
and HttpResponseMessage
to execute a lot of requests.
If I do responseMessage.Headers.GetValues("whatever")
, this seem to take a LOT of time, reducing my program's speed by almost 200%.
Here's a minimal reproducible example:
var httpClient = new HttpClient();
using var requestMessage = new HttpRequestMessage(HttpMethod.Get, "https://api.example.com/x");
var responseMessage = await httpClient.SendAsync(requestMessage);
var accessToken = responseMessage.Headers.GetValues("X-Anything"); // Without this line, my program runs almost 200% faster
I am using .NET Core 3 on Windows 10 to run this code.
Why that? Is there a workaround? This is a real problem.