【问题标题】:I get this error while using HTML Agility Pack: system.net.http.httprequestexception' in mscorlib.dll在 mscorlib.dll 中使用 HTML Agility Pack: system.net.http.httprequestexception' 时出现此错误
【发布时间】:2020-03-02 17:37:46
【问题描述】:

我有一个网络抓取应用程序,我在其中从网站检索信息。 直到昨天它都工作正常,现在我遇到了错误。

之前的错误是如上所述。 现在,它包括:

无法建立 SSL 连接,请参阅内部异常。 Security.Authentication.AuthenticationException:身份验证失败。

但是,我得到了这些错误。

有人可以帮忙吗?

try
            {
                var httpClient = new HttpClient();
                var html = await httpClient.GetStringAsync(url);

                var htmlDocument = new HtmlDocument();
                htmlDocument.LoadHtml(html);

                var webListHtml = htmlDocument.DocumentNode.Descendants("td")
                    .Where(node => node.GetAttributeValue("style", "")
                    .Equals("font-weight: bold; font-size:16px; text-align:left; padding-left:5px; padding-top:10px; padding-bottom:10px"));

        }
        catch (Exception e)
        {
            Console.WriteLine("I caught the error" + e.ToString());
        }

【问题讨论】:

    标签: c# web httpclient dotnet-httpclient


    【解决方案1】:

    您可能会看到这是否有效:

    ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
    

    但请记住,从安全角度来看,这不是一个好主意。您必须在这里决定是否适合您的目的。

    【讨论】:

    • 感谢您的回答。不幸的是,它不起作用。我正在开发个人机器和个人项目,因此安全性不是问题。我的意思是,我不明白的是,它在几个小时前工作得非常好。我没有改变任何东西,它给了我这些错误。
    • @mrkn0007 嗯...某处发生了一些变化...我最近有一个 .Net Framework Cumulative Update 破坏了一些简单的代码...作为下一步,我建议检查服务器的证书网页浏览器。您也可以查看ServicePointManager.SecurityProtocol。我猜你不拥有服务器,或者你不会废弃它......很多公司正在将所有东西都切换到 TLS 并放弃 SSL。例如,我认为 Stack Overflow 最近就是这样做的。因为您的问题始于当月的第一天(工作天),这似乎是合理的。我希望这会有所帮助!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-29
    • 1970-01-01
    • 1970-01-01
    • 2011-09-05
    • 2014-05-04
    相关资源
    最近更新 更多