即使它在浏览器中工作,是什么让这个 HTTPS WebRequest 超时? [英] What makes this HTTPS WebRequest time out even though it works in the browser?

查看:32
本文介绍了即使它在浏览器中工作,是什么让这个 HTTPS WebRequest 超时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的要求:

var request = (HttpWebRequest) WebRequest.Create("https://mtgox.com/");
request.CookieContainer = new CookieContainer();
request.AllowAutoRedirect = false;
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.Headers[HttpRequestHeader.AcceptEncoding] = "gzip, deflate";
request.Headers[HttpRequestHeader.AcceptLanguage] = "en-gb,en;q=0.5";
request.Headers[HttpRequestHeader.AcceptCharset] = "ISO-8859-1,utf-8;q=0.7,*;q=0.7";
request.Timeout = 5000;
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:2.0) Gecko/20100101 Firefox/4.0";
request.Method = "GET";

request.GetResponse();

标题是使用 HttpFox 从 Firefox 复制的.我使用 Fiddler2 来验证至少对于 HTTP 请求,Firefox 请求和我的请求之间的标头完全相同.

The headers were copied from Firefox using HttpFox. I used Fiddler2 to verify that at least for HTTP requests, the headers are completely identical between Firefox requests and my requests.

但是,当使用 HTTPS 向这个特定网站发出请求时,请求就会超时.它适用于其他网站.

However, when performing a request to this specific website using HTTPS, the request simply times out. It works for other websites.

我必须以与 Firefox 不同的方式执行它,因为它在 Firefox 中始终有效.但是,我无法使用 Fiddler2 对其进行调试,因为每当 Fiddler2 转发这些请求时,它们也会超时,即使是由 Firefox 发起的.

I must be performing it differently to Firefox, because it always works in Firefox. I can't debug it using Fiddler2, however, because whenever Fiddler2 forwards these requests they also time out, even when originated by Firefox.

这只是一个有问题的网站吗?以上哪一部分让我觉得我不是 Firefox?

Is it just a really buggy website? Which part of the above gives me away as not being Firefox?

推荐答案

使用 Microsoft Network Monitor,我发现 HttpWebRequest 会卡在它应该发回客户端密钥交换的阶段.它根本没有.服务器等待它,但它没有来.

Using Microsoft Network Monitor, I found that HttpWebRequest would get stuck at a stage where it's supposed to send back a client key exchange. It simply didn't. The server duly waited for it, but it never came.

修复它是强制 HttpWebRequest 使用 SSL3 而不是 TLS(即使 TLS 应该在必要时自动转换为 SSL3):

What fixed it was forcing HttpWebRequest to use SSL3 instead of TLS (even though TLS is supposed to automatically turn into SSL3 if necessary):

ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;

为什么会这样,我想我永远不会知道 - 只是那些比我认识的任何人都愿意花费更多时间来弄清楚的神秘事物之一......

Why this is so I guess I'll never know - just one of those mysterious things that would take more time to figure out than anyone I know is willing to spend...

捕获的不同之处在于:TLS 变体 有一个警报"服务器 Hello 响应中的条目,SSL3 交换以及所有实际工作的 TLS 交换中都不存在该条目.不过,奇怪的是,Firefox 成功执行请求的捕获中也出现了相同的警报.

One thing that was different about the captures: the TLS variant had an "Alert" entry in the Server Hello response, which is absent from the SSL3 exchange and also from all the TLS exchanges that actually worked. Curiously, though, the same alert is present in a capture of Firefox performing the request successfully.

最后,当我第一次发布这个问题时,似乎有一个临时的 OCSP 故障,此后已解决.这增加了混乱,但不是核心问题.

Finally, it appears that there was a temporary OCSP glitch just when I was first posting this question, which has since been resolved. This added to the mess, but isn't the core problem.

这篇关于即使它在浏览器中工作,是什么让这个 HTTPS WebRequest 超时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆