ServicePointManager.SecurityProtocol

.NET40兼容,默认框架越新集成的TLS协议版本就越高,最新最安全的是TLS1.3版本。

        [SecurityCritical]
        [SecuritySafeCritical]
        private static void InitialSecurityProtocol()
        {
            try
            {
                ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                              | SecurityProtocolType.Tls
                                              | (SecurityProtocolType)0x300 // Tls11
                                              | (SecurityProtocolType)0xC00 // Tls12
                                              | (SecurityProtocolType)0x3000; // Tls13
            }
            catch (Exception)
            {
                try
                {
                    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                  | SecurityProtocolType.Tls
                                                  | (SecurityProtocolType)0x300 // Tls11
                                                  | (SecurityProtocolType)0xC00; // Tls12
                }
                catch (Exception)
                {
                    try
                    {
                        ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                        | SecurityProtocolType.Tls
                                                        | (SecurityProtocolType)0x300; // Tls11
                    }
                    catch (Exception)
                    {
                        try
                        {
                            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                                            | SecurityProtocolType.Tls;
                        }
                        catch (Exception) { }
                    }
                }
            }
        }

上一篇:Ubuntu设置一个简单的密码【绕过检测版】


下一篇:https网站访问第三方https网站时候报错: The request was aborted:Could not create SSL/TLS secure channel.