C# How to set HttpClient Keep-Alive to false

前端 未结 5 1693
一生所求
一生所求 2020-12-14 01:40

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

5条回答
  •  不思量自难忘°
    2020-12-14 02:21

    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");
    

提交回复
热议问题