解决https调用出现【基础连接已经关闭: 未能为 SSL/TLS 安全通道建立信任关系】错误

在HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);前面添加
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult);
CheckValidationResult方法
 public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors)
{  // 总是接受  
  return true;
}

 

posted @ 2020-12-18 16:08  昵称已存在嘿  阅读(861)  评论(0编辑  收藏  举报