简体   繁体   English

机器特定的HttpWebResponse超时

[英]Machine-Specific HttpWebResponse Timeout

I have a very odd machine-specific issue. 我有一个非常奇怪的机器特定问题。 On some machines, the code below works, on others it freezes until a timeout exception is thrown on by GetResponse() call. 在某些机器上,下面的代码有效,在其他机器上,它冻结直到GetResponse()调用引发超时异常。

string url = "https://myserver/myimage.png";

System.Net.ServicePointManager.ServerCertificateValidationCallback = ((sender, certificate, chain, sslPolicyErrors) =>
{
     return true;
});

HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
req.Method = "GET";
req.AllowAutoRedirect = false;

try
{
    using (HttpWebResponse resp = (HttpWebResponse)req.GetResponse())
    {
        Console.WriteLine("Success");
    }
}
catch (Exception ex)
{
    Console.WriteLine("Error: " + ex.ToString());
}

Console.ReadKey();

I can't find any OS/configuration pattern between the machines that work and the ones that fail. 我在工作的机器和失败的机器之间找不到任何操作系统/配置模式。 This is a console application running with an administrator user. 这是一个与管理员用户一起运行的控制台应用程序。

The only particular thing about this is that the URL being accessed is an image running into a test server that is using a self-issued SSL certificate, so it needed the workaround using ServerCertificateValidationCallback displayed in the code above. 唯一需要注意的是,要访问的URL是运行在使用自发SSL证书的测试服务器中的映像,因此需要使用上面代码中显示的ServerCertificateValidationCallback的变通方法。

Other URLs I tested worked properly. 我测试的其他URL正常运行。

Can anyone help me identify possible causes for this issue and workarounds? 谁能帮助我确定此问题和解决方法的可能原因?

As usual, it's quite simple once you figure it out: The machines where the problem was not present had .Net Framework 4.5 installed. 和往常一样,一旦弄清楚,它就非常简单:不存在问题的计算机已安装.Net Framework 4.5。

This is very likely due to the fact that 4.5 is an in-place update for 4.0, and includes several bugfixes to the core libraries. 这很可能是由于4.5是4.0 的就地更新 ,并包含对核心库的若干错误修正。

I've had the same issue on Win7 , VS2010 and it was solved by windows update - update to .NET 4.5.1 我在Win7和VS2010上遇到了相同的问题并且通过Windows Update解决了 - 更新到.NET 4.5.1
Another thing worth mentioning that it happens only in specific servers as well , not only specific clients. 值得一提的另一件事是,它仅在特定的服务器中发生, 而不仅在特定的客户端中发生。
(i would post as comment but not enough ratings) (我会发表评论,但没有足够的评分)
Did anyone solve this without using windows update ? 没有人解决此问题而不使用Windows Update吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM