I had a low performance problem with HTTP requests on .NET. The HTTP GET request to a REST API on the localhost took about 500 ms to complete. I spent a lot of time to fix i
I hope this can help you, I have tested
_client.DefaultRequestHeaders.Connection.Add("Keep-Alive");
Use this code to disable HTTP Keep-Alive on the client:
_http.DefaultRequestHeaders.ConnectionClose = true;
This will set Connection
request header to close
.
When you set HttpWebRequest.KeepAlive = true
the header set is Connection: keep-alive
When you set HttpWebRequest.KeepAlive = false
the header set is Connection: close
So you will need
_http.DefaultRequestHeaders.Add("Connection", "close");
I wrote HttpClientHandler, and in the handler just before the request I deleted the header "Connection". In this case, it sets the default "Connection: keep-alive". Even if before that you put it in the HttpClient by default, set properties, etc. Check your handlers.
See code below:
HttpClient cli;
...
cli.DefaultRequestHeaders.Add("Connection", "keep-alive");
cli.DefaultRequestHeaders.Add("Keep-Alive", "600");