我正在尝试将现有的类库代码转换为.NET Core类库。在static
构造函数中的代码中,我具有以下内容:
ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.Expect100Continue = false;
我进行了一些搜索,并且
ServicePointManager
在.NET Core中不再可用,并且现在应使用WinHttpHandler
(ServicePointManager.DefaultConnectionLimit in .net core?)。我的问题是
ServicePointManager
到底是什么,正在设置的属性是什么?WinHttpHandler
不是static
,所以我必须创建一个实例来设置这些属性?我需要更改所有http调用以使用该实例吗?
最佳答案
WinHttpHandler
继承自HttpMessageHandler
,因此在构造HttpClient
时可以将其作为参数传递,如下所示:
WinHttpHandler httpHandler = new WinHttpHandler();
httpHandler.SslProtocols = SslProtocols.Tls12;
HttpClient client = new HttpClient(httpHandler);
希望这可以帮助!
关于asp.net-core - ASP.NET Core中的ServicePointManager,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39560249/