1、更新.NET Framework版本:确保你的.NET Framework版本至少为4.6或更高。这是因为.NET Framework 4.6及以上版本对SSL/TLS的支持有所改进,能够更好地处理新的安全协议。如果你的本地开发环境是Windows 10,可能不会遇到这个问题,因为Windows 10通常支持较新的安全协议。但是,如果你的服务器环境是较旧的Windows Server 2008,可能需要升级.NET Framework以兼容新的安全协议。
2、确保客户端启用了与服务器匹配的安全协议:如果服务端更改了安全协议,客户端也需要相应地更新其安全协议设置。这可以通过在代码中设置ServicePointManager.SecurityProtocol属性来实现。例如,如果服务端支持TLS 1.2,客户端应该确保ServicePointManager.SecurityProtocol包含了SecurityProtocolType.Tls12。如果服务端支持多种协议,客户端可以尝试启用所有可用的协议,以确保兼容性。
3、代码执行前加如下
ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls; ServicePointManager.ServerCertificateValidationCallback = (sender, certificate, chain, errors) => true; 或者 ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;或者
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | (SecurityProtocolType)0x300 //Tls11 | (SecurityProtocolType)0xC00; //Tls12
发表评论