How do I reuse an HTTP connection for multiple requests?

I am making an application that constantly scans the remote website for any changes. I use System.Net.Http.HttpClient

, but I noticed that it probably doesn't support connection reuse.

The requests are executed one after the other, but they usually take about 250ms. When I have Fiddler enabled with the Reconnect to Server option, it drops to 150ms per request.

I think I have configured incorrectly HttpClient

, but I cannot find any information in the MSDN link that would help me solve the problem.

+3


source to share


1 answer


For HttpWebRequest, you need to set the property KeepAlive

.

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

.



The keep-alive connection does not work with System.Net.Http.HttpClient on certain hosts may be connected.

0


source







All Articles