gpt4 book ai didi

c# - 忽略无效的 SSL 证书

转载 作者:可可西里 更新时间:2023-11-01 08:49:03 24 4
gpt4 key购买 nike

我正在尝试从我们的子版本中打印出日志消息。但我正在努力绕过无效的 SSL 证书。这是错误:

OPTIONS of 'https://xxxxx/svn/SiteFabrics/trunk/AppLaunch/Bloc/Frontend': Server certificate verification failed: certificate issued for a different hostname, issuer is not trusted (https://xxxx)

我忽略证书错误的尝试是添加这一行:

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

然而,这没有任何区别,因为 .net 错误仍然相同。下面是代码,谁能看出我做错了什么?

        using (SvnClient client = new SvnClient())
{
Collection<SvnLogEventArgs> list;
client.Authentication.DefaultCredentials = new NetworkCredential("user", "pass");

ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

SvnLogArgs la = new SvnLogArgs(); //{ Start=128; End=132; };
client.LoadConfiguration(Path.Combine(Path.GetTempPath(), "Svn"), true);
client.GetLog(new Uri("https://[svnurl]"), la, out list);
ViewBag.SVNLog = list;
}

最佳答案

找到这个问题的解决方案:

首先添加这个:

        static void SVN_SSL_Override(object sender, SharpSvn.Security.SvnSslServerTrustEventArgs e)
{
e.AcceptedFailures = e.Failures;
e.Save = true;
}

然后替换我原来的魔法线:

            ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => true;

用这个:

client.Authentication.SslServerTrustHandlers += new EventHandler<SharpSvn.Security.SvnSslServerTrustEventArgs>(SVN_SSL_Override);

关于c# - 忽略无效的 SSL 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8121189/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com