标签:play man manage htm ring event ice tls inter
早上使用.Net WebClient类采集亚马逊数据,返回http 400 Bad Request错误,内容里面有“我们检测到您的浏览器不兼容传输层安全协议 (TLS) 1.1 或更高版本,此协议在 Internet 上用于确保您通信的安全性。”
所以就想着可能是WebClient使用TLS版本过低,查了下资料,全局加上这段代码。
ServicePointManager.ServerCertificateValidationCallback += ValidateRemoteCertificate;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
/// <summary> /// Certificate validation callback. /// </summary> private static bool ValidateRemoteCertificate(object sender, X509Certificate cert, X509Chain chain, SslPolicyErrors error) { // If the certificate is a valid, signed certificate, return true. if (error == System.Net.Security.SslPolicyErrors.None) { return true; } Console.WriteLine("X509Certificate [{0}] Policy Error: ‘{1}‘", cert.Subject, error.ToString()); return false; }
参考链接:https://stackoverflow.com/questions/20064505/requesting-html-over-https-with-c-sharp-webclient
我们检测到您的浏览器不兼容传输层安全协议 (TLS) 1.1 或更高版本,此协议在 Internet 上用于确保您通信的安全性。
标签:play man manage htm ring event ice tls inter
原文地址:https://www.cnblogs.com/lhking/p/11022607.html