C# .NET Framework .NET Core 设置 SecurityProtocol, The requested security protocol is not supported

The requested security protocol is not supported. 解决办法

        public static void Init()
        {
#if NETSTANDARD || NET5_0_OR_GREATER
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
#else
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3
                                    | SecurityProtocolType.Tls
                                    | SecurityProtocolType.Tls11
                                    | SecurityProtocolType.Tls12;
#endif
            ServicePointManager.ServerCertificateValidationCallback = (a, b, c, d) => { return true; };
            ServicePointManager.CheckCertificateRevocationList = true;
            ServicePointManager.DefaultConnectionLimit = 1000;
            ServicePointManager.Expect100Continue = false;
        }

作者最新文章
C# 实现字符串文本换行的方法,文本如何换行
C# 如何循环读取文件每一行文本内容
C# DateTime AddMonths 的错误用法导致跳过日期
C# 全角转换半角,半角转换为全角
C# Word 转换 PDF 文件,如何转换 PDF