I use System.Net.Http.HttpClient to send a sequence of requests from a console application to the REST API and deserialize JSON responses to strongly typed objects. My implementation is as follows:
using (var client = new HttpClient()) { var content = new StringContent(data, Encoding.UTF8, "text/html"); var response = client.PostAsync(url, content).Result; response.EnsureSuccessStatusCode(); return response.Content.ReadAsAsync<MyClass>().Result; }
However, I had a problem very similar to that described in this question , in which everything works fine when requests are sent through Fiddler, but it hangs after the 4th or 5th request when Fiddler is disabled.
If the cause of the problem is the same, I assume that I need to do something else with HttpClient in order to completely free resources after each request, but I can not find code samples that show how to do this.
Hoping someone can point me in the right direction.
Thank you very much,
Tim
source share