runliuv

runliuv@cnblogs

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

 

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);

 

posted on 2021-01-20 10:42  runliuv  阅读(712)  评论(0编辑  收藏  举报