请求被中止: 未能创建 SSL/TLS 安全通道 .NET

 

.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; //加上这一句

 

请求被中止: 未能创建 SSL/TLS 安全通道 .NET

上一篇:ThinkPHP 5日志文件包含trick


下一篇:Oracle迁移至PostgreSQL工具之Ora2Pg