public static bool CheckValidationResult(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors errors) { #region 自签名证书,跳过 if (!string.IsNullOrWhiteSpace(certificate.Subject)) { var subjectNames = certificate.Subject.Split(','); foreach (var subjectName in subjectNames) { if (subjectName.Equals("CN=05864111")) { return true; } } } #endregion //合法证书机构的,正常校验 if (errors == SslPolicyErrors.None) return true; return false; }
"CN=05864111" 根据自己实际情况修改。
使用:
ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(HttpUtil.CheckValidationResult);