如何抑制 HTTPWebRequest 期间出现的安全风险通知

发布于 2024-10-19 13:41:35 字数 559 浏览 0 评论 0原文

当我向某些网站发送 HTTPWebRequest 时,我收到一条弹出消息,指出该网站存在指定的安全风险,我是否要继续。直到 HTTPWebRequest 被检索并存储为字符串(下面代码中的 ResponseAsString)之后,该消息才会出现。 HTTPWebrequest 检索网页文本,随后使用以下代码将其转换为 IHTMLDocument2。警告出现在命令上 - oDoc.close(); try-catch 块不会产生显示错误。有什么办法可以抑制这个消息吗?

//Creates IHTMLDocument2 frow WebRequest!
private IHTMLDocument2 GetIHTMLDoc2FromString(string ResponseAsString) 
{
   HTMLDocument ProfileHTML = new HTMLDocument(); 
   IHTMLDocument2 oDoc = (IHTMLDocument2)ProfileHTML; 
   oDoc.write(ResponseAsString);
   oDoc.close();
   return oDoc; 
}

When I send HTTPWebRequests to certain web sites I get a popup message stating that there us an upspecified Security Risk associated with the site and do I want to continue. The message does not occur until after the HTTPWebRequest has been retrived and stored as a string (ResponseAsString in the code below). The HTTPWebrequest retrieves the text of a webpage which is subsequently converted into an IHTMLDocument2 with the code that follows. The warning occurs on the command -- oDoc.close(); A try-catch block does not yield show an error. Is there any way to suppress this message?

//Creates IHTMLDocument2 frow WebRequest!
private IHTMLDocument2 GetIHTMLDoc2FromString(string ResponseAsString) 
{
   HTMLDocument ProfileHTML = new HTMLDocument(); 
   IHTMLDocument2 oDoc = (IHTMLDocument2)ProfileHTML; 
   oDoc.write(ResponseAsString);
   oDoc.close();
   return oDoc; 
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深海蓝天 2024-10-26 13:41:35

使用此代码

 public static bool IgnoreInvalidSSL { get; set; }
    private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
    {
        if (IgnoreInvalidSSL)
        {
            return true;
        }
        else
        {
            return policyErrors == SslPolicyErrors.None;
        }
    }

然后在您的 httprequest 上使用

ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);

use this code

 public static bool IgnoreInvalidSSL { get; set; }
    private static bool ValidateRemoteCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors policyErrors)
    {
        if (IgnoreInvalidSSL)
        {
            return true;
        }
        else
        {
            return policyErrors == SslPolicyErrors.None;
        }
    }

Then on your httprequest use

ServicePointManager.ServerCertificateValidationCallback += new System.Net.Security.RemoteCertificateValidationCallback(ValidateRemoteCertificate);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文