C# How to set HttpClient Keep-Alive to false

前端 未结 5 1712
一生所求
一生所求 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条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-14 02:19

    Use this code to disable HTTP Keep-Alive on the client:

    _http.DefaultRequestHeaders.ConnectionClose = true;
    

    This will set Connection request header to close.

提交回复
热议问题