gpt4 book ai didi

c# - RemoteCertificateValidationCallback 放在哪里?

转载 作者:太空宇宙 更新时间:2023-11-03 17:22:25 33 4
gpt4 key购买 nike

我和这里有同样的问题:How to disable "Security Alert" window in Webbrowser control

我喜欢这个答案,但我要将 ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate); 放在哪里?

我使用以下代码提交学校网络的登录页面后收到“无效认证”消息:

HtmlElementCollection ellements = webBrowser.Document.GetElementsByTagName("input");
foreach (HtmlElement ellement in ellements)
{
if (ellement.OuterHtml == "<INPUT onclick=\"this.value = 'Submitted'\" value=\" Login \" type=submit>")
{
ellement.InvokeMember("click");
this.DialogResult = DialogResult.OK;
break;
}
}

最佳答案

在显示 Web 浏览器控件/提交页面之前,您应该在任何点放置以下内容:

ServicePointManager.ServerCertificateValidationCallback += 
new RemoteCertificateValidationCallback((sender, certificate, chain, policyErrors) => { return true; });

(这与链接问题中的示例答案完全相同,但回调方法是匿名的,因此更加紧凑)。

关于c# - RemoteCertificateValidationCallback 放在哪里?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5042982/

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