.NET 4.0
using (WebClient wc = new WebClient()) { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; var data = wc.DownloadData(url); string html = Encoding.GetEncoding("UTF-8").GetString(data); }
.NET 4.5
方法一:
ServicePointManager.ServerCertificateValidationCallback = Callback;//请求前
/// <summary> /// 针对https 域名 /// </summary> /// <param name="sender"></param> /// <param name="certificate"></param> /// <param name="chain"></param> /// <param name="sslPolicyErrors"></param> /// <returns></returns> private static bool Callback(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; }
方法二:
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; //加上这一句