【问题标题】:.Net, WebClient, DownloadString fails for one site ("The underlying connection was closed...")一个站点的 .Net、WebClient、DownloadString 失败(“底层连接已关闭...”)
【发布时间】:2015-09-25 06:48:30
【问题描述】:

我正在使用 .Net(框架 3.5)以类似的方式访问许多网站以获取数据(用于 Wikipedia)。现在我遇到了一个我无法访问的站点。我收到一个异常“底层连接已关闭”。该站点使用 SSL (https),​​但我不知道这是否会引发问题。我已经阅读了许多主题并尝试了许多建议,但对我来说还没有任何效果。我也尝试过 OpenRead / ReadToEnd,它也失败了。我必须承认,我对 HTTP 的了解非常有限。

该网站是https://www.infoflora.ch

非常欢迎任何建议!

杰尔

这是我的代码示例:

class WebClientDBLink : WebClient
{
    public WebClientDBLink()
    {
        UseDefaultCredentials = true;
        Encoding = Encoding.UTF8;
        Headers.Add("Content-Type", Bot.webContentType);
        Headers.Add("User-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)");
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        HttpWebRequest wr = (HttpWebRequest)base.GetWebRequest(address);
        wr.CookieContainer = new CookieContainer();
        // wr.KeepAlive = false;
        // wr.Timeout = 100000;
        return wr;
    }
}
...

    String sUrl = "https://www.infoflora.ch/de/flora/2906-.html"; // just one exampl

    String sText = "";

    try
    {

        ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
        // ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

        Uri res = new Uri(sUrl);
        WebClient wc = new WebClientDBLink();
        sText = wc.DownloadString(res);
    }
    catch (Exception e)
    {
        ...
        return false;
    }

【问题讨论】:

  • 你是在 Windows XP 上运行这个吗?
  • 是的,它在 Windows XP 上运行。对不起,我忘记了。

标签: .net ssl webclient


【解决方案1】:

这个:

该网站使用 SSL (https),​​但我不知道这是否会引发问题。

结合您的评论:

是的,它在 Windows XP 上运行

给出提示:)

https://infoflora.ch 的端点仅支持相当现代的密码套件(CBC 模式下的 AES 和 CAMELLIA 以及 AES-GCM)- Windows XP 上都不支持。

如果您希望它工作,请使用 Windows 7 或更新版本(您知道 Windows XP 不再受支持吗?)

【讨论】:

  • 你是对的!它在Windows 7下运行没有任何问题! (“不再支持”你也是对的,但是......)。尊重用这么少的信息解决这个问题。非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-05-31
  • 2023-03-27
  • 2016-11-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-27
相关资源
最近更新 更多