gpt4 book ai didi

c# - 在 HttpClient C# 中支持 TLS 1.2

转载 作者:行者123 更新时间:2023-12-03 19:43:32 24 4
gpt4 key购买 nike

下午好!
我使用 HttpClient 使用 Azure Maps API。
如何启用对 TLS 1.2 的支持?
据我所知,在 Framework 4.6+ 中它是受支持的。我不应该为此做任何事情吗?

最佳答案

使用ServicePointManager设置安全协议(protocol)。

Gets or sets the security protocol used by the ServicePoint objects managed by the ServicePointManager object.


HttpClient httpClient = new HttpClient();   

//specify to use TLS 1.2 as default connection
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

This property selects the version of the Secure Sockets Layer (SSL) or Transport Layer Security (TLS) protocol to use for new connections; existing connections aren't changed.

Starting with the .NET Framework 4.7, the default value of this property is SecurityProtocolType.SystemDefault. This allows .NET Framework networking APIs based on SslStream (such as FTP, HTTP, and SMTP) to inherit the default security protocols from the operating system or from any custom configurations performed by a system administrator.

关于c# - 在 HttpClient C# 中支持 TLS 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59388038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com