6

I'm making an application which constantly scans remote website for any changes. I'm using System.Net.Http.HttpClient, but I noticed that it probably doesn't support reusing connection.

Requests are executed one after one, but normally they take about 250 ms to be completed. When I have Fiddler turned on with "Reuse server connections" option on, it drops to as low as 150 ms per request.

I guess I have misconfigured HttpClient, but I can't find any information in MSDN reference which would help me to solve the problem.

stil
  • 5,306
  • 3
  • 38
  • 44
  • May be Http connection pooling is the answer. You can look for: http://stackoverflow.com/questions/15085708/is-http-connection-pooling-possible – shrekDeep Nov 07 '14 at 12:27
  • HttpWebRequest is "obsolete (does not compile) in 4.5.2 and later". http://msdn.microsoft.com/en-us/library/cc190216%28v=vs.110%29.aspx – stil Nov 07 '14 at 14:11
  • I'm thinking of HTTP1.0 actually. Looking for the answer. – Grigory Kornilov Nov 07 '14 at 14:28

1 Answers1

1

For a HttpWebRequest, you would need to set the KeepAlive property.

HttpClient doesn't appear to offer a similar property, but it probably attempts to use keepalive by default. What are the request and response headers? (HTTP/1.0 only supports keepalive if the server explicitly sends a Connection: Keep-alive response header.

Connection keep-alive not working with System.Net.Http.HttpClient on certain hosts may be related.

Community
  • 1
  • 1
EricLaw
  • 56,563
  • 7
  • 151
  • 196