Why is the first call to HttpClient.PostAsync extremely slow in my c # winforms application?

I have an httpclient like this:

var client = new HttpClient(); 

I am writing to you like this:

 var result = client.PostAsync( endpointUri, requestContent); 

And get an answer like this:

 HttpResponseMessage response = result.Result; 

I understand that this call blocks the thread, this is how it should work (just creating a tool for yourself, no need for asynchronous threads)

The first time I run this call, it takes about 2 minutes to get the result. Meanwhile, if I make the same call elsewhere, it will be done in 200 ms. Even if I hit Google, it will take 2 minutes. But, after the first call, while I open the application, any additional calls are good. Its just the first feces when I open the app. What could be the reason for this?

+7
source share
1 answer

The problem was that he hung for a very long time trying to resolve proxies for the client. Initializing HttpClient as the trick did:

 var client = new HttpClient(new HttpClientHandler { UseProxy = false }); 
+12
source

All Articles