SSL 链接安全协议的enum

时间:2024-07-17 15:07:44

摘自:https://blog.****.net/lan_liang/article/details/70948221

在进行HTTPS连接时,需要指定SecurityProtocol。对于.NET 4.0的代码,需要强制转换。

...

System.Net.ServicePointManager.SecurityProtocol = (SecurityProtocolType) 192 |
(SecurityProtocolType) 768 |
(SecurityProtocolType) 3072;
...

在 .net 4.5以上的代码使用以下代码即可。

System.Net.ServicePointManager.SecurityProtocol =
System.Net.SecurityProtocolType.Ssl3
| System.Net.SecurityProtocolType.Tls12
| SecurityProtocolType.Tls11
| SecurityProtocolType.Tls;