我正在向第 3 方 Web 服务发送基本请求,但在安装了 .net v4.0 的机器上它总是超时。 (超时异常:“操作已超时”)
如果安装 4.5 就可以正常工作,但我们需要支持 4.0
服务主机已禁用对 SSL3 协议(protocol)的支持,因此以下内容对我不起作用。
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
发送请求的代码是基本的
var request = ((HttpWebRequest)WebRequest.Create("https://hostname.com"));
var response = (HttpWebResponse)request.GetResponse(); //timeout here
这也无济于事,因为它永远不会达到这一点
ServicePointManager.ServerCertificateValidationCallback = (sender,certificate,chain,sslPolicyErrors)=> true;
如果我只是使用网络浏览器导航到它,第 3 方网络服务工作正常。
在这种情况下,延长超时值显然不起作用,因为第 3 方服务器实际上从未返回响应。
我该怎么做才能解决这个问题?
更新: 该问题发生在 win7 和 win server 2003 机器上。 另一项测试是在装有 .NETv4.0 的 XP 机器上完成的。测试通过并收到回复。 所以.NETv4.0 可能不是这里的问题。 (但升级到 4.5 确实解决了之前的问题。)
问题一定是环境问题。我该怎么做才能解决此问题?
最佳答案
找到 dotwilbert 的答案 here
The .NET framework on Windows 7 implements a TLS extension: Server Name Indication (RFC4366). According to your post What does this TLS Alert mean the server is responding with "Unrecognized Name". Not sure why the connection is reported to time out, because it really doesn't. Your network traces should show that the client initiates a connection termination after this [FIN,ACK]. Downgrading to SSL3 avoids the invocation of the the SNI.
FYI: The same .NET framework on Windows XP does not use the TLS Server Name Indication Extension. Your program will work there....
In my case I traced the occurrence of this to a missing ServerName directive in Apache. Adding the ServerName to the SSL configuration solved it, because now the web server no longer is unaware of its name.
第 3 方更新了 SSL 配置以包含服务器名称,问题已解决。
关于c# - 使用 HTTPS/TLS 的 Web 请求导致超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25300961/