HttpClientHandler / HttpClient Memory Leak

后端 未结 4 1415
逝去的感伤
逝去的感伤 2020-12-03 01:24

I have anywhere from 10-150 long living class objects that call methods performing simple HTTPS API calls using HttpClient. Example of a PUT call:



        
4条回答
  •  [愿得一人]
    2020-12-03 02:04

    This is how I change the HttpClientHandler proxy without recreating the object.

    public static void ChangeProxy(this HttpClientHandler handler, WebProxy newProxy)
    {
        if (handler.Proxy is WebProxy currentHandlerProxy)
        {
            currentHandlerProxy.Address = newProxy.Address;
            currentHandlerProxy.Credentials = newProxy.Credentials;
        }
        else
        {
            handler.Proxy = newProxy;
        }
    }
    

提交回复
热议问题