复制代码
// 版本4.0-4.4用这句话 指定http请求使用Tls1.2
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072;

// 版本4.5用这句话 指定http请求使用Tls1.2
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

// 版本大于4.5用这句话 指定http请求使用Tls1.1、Tls.2
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;

//若设置Tls还是请求失败,则需要加上下面代码
ServicePointManager.ServerCertificateValidationCallback = (s, cert, chain, error) => true;
 
复制代码