ASP.NET Core中的ServicePointManager
问题描述:
我试图将现有的类库代码转换为.NET Core类库。在一个static
构造函数的代码,我有以下几点:ASP.NET Core中的ServicePointManager
ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.Expect100Continue = false;
我做了一些搜索和ServicePointManager
不再.NET提供的核心,并WinHttpHandler
现在应该使用(ServicePointManager.DefaultConnectionLimit in .net core?)。
我的问题是究竟是什么ServicePointManager
,什么是正在设置的属性?
WinHttpHandler
不是static
作为ServicePointManager
所以我必须创建一个实例来设置这些属性?我是否需要更改所有的http调用以使用该实例?从HttpMessageHandler
答
WinHttpHandler
继承,这样你就可以施工时把它作为一个参数,你HttpClient
喜欢如下:
WinHttpHandler httpHandler = new WinHttpHandler();
httpHandler.SslProtocols = SslProtocols.Tls12;
HttpClient client = new HttpClient(httpHandler);
希望这有助于!