asp.net-core - ASP.NET Core中的ServicePointManager

标签 asp.net-core .net-core asp.net-core-1.0

我正在尝试将现有的类库代码转换为.NET Core类库。在static构造函数中的代码中,我具有以下内容:

ServicePointManager.DefaultConnectionLimit = 100;
ServicePointManager.Expect100Continue = false;


我进行了一些搜索,并且ServicePointManager在.NET Core中不再可用,并且现在应使用WinHttpHandlerServicePointManager.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/

相关文章:

c# - 用源代码替换对 Json.NET 的引用时无法编译项目

Ubuntu 上的 ASP.NET 核心

asp.net-core - ASP.NET Core : A compatible SDK version for global. json 版本 2.1.400 未找到

c# - 一个服务,两个实例,如何使用 ASP.NET Core DI 进行配置?

c# - 在 VS 2017 中的预构建事件中使用 protoc 从 .proto 文件生成 c# 文件

c# - 更改单个 ASP.NET Core Controller 的 JSON 序列化设置

asp.net-core-mvc - 如何在asp.net core 1.0中添加迁移

asp.net-core - Visual Studio - 无效的 URI : The hostname could not be parsed

c# - Entity Framework 核心过滤器 DbSet

c# - "Predefined type ' System.* ' is not defined or imported"错误,visual studio 代码,omnisharp