Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9063213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T15:56:06+00:00 2026-06-16T15:56:06+00:00

I am using System.Net.Http.HttpClient to post a sequence of requests from a console application

  • 0

I am using System.Net.Http.HttpClient to post a sequence of requests from a console application to a REST API and to deserialize the JSON responses into strongly-typed objects. My implementation is like this:

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 am experiencing a problem very similar to one described in this question, whereby everything works fine when the requests are routed via 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 I need to do something more with HttpClient to get it to fully release its resources after each request but I am unable to find any code samples that show how to do this.

Hoping somebody can point me in the right direction.

Many thanks,

Tim

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T15:56:10+00:00Added an answer on June 16, 2026 at 3:56 pm

    You are not disposing of the HttpResponseMessage object. This can leave open streams with the server, and after some quota of streams with an individual server is filled, no more requests will be sent.

    using (var client = new HttpClient())
    {
        var content = new StringContent(data, Encoding.UTF8, "text/html");
        using(var response = client.PostAsync(url, content).Result)
        {    
            response.EnsureSuccessStatusCode();
            return response.Content.ReadAsAsync<MyClass>().Result;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using System.Net.Http.HttpClient to access a rest service. This code compiles and runs
using (var client = new System.Net.Http.HttpClient()) { var response = client.GetAsync(fullUrl).Result; } I am
I get security exception when using System.Net.WebClient to do HTTP requests, which is due
I want to call the google url shortner API from my C# Console Application,
I tried creating a simple HTTP server using System.Net.HTTPListener, but it doesn't receive connections
I'm using System.Net tracing as described here: http://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html But that traces every request made
I'm basically running the example here: http://msdn.microsoft.com/en-us/library/system.net.httplistener.begingetcontext.aspx using System; using System.Collections.Generic; using System.Linq; using
I'm trying to connect to a third party application API using apache commons HTTP
I can ping using console app, but I want to ping from ASP.NET, the
I'm trying to post some XML to a an exposed service. I'm using System.Net.WebRequest

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.