[英]HttpWebRequest.GetResponse Operation has timed out
I'm trying to get simple gzip encoded html response from a website and it keeps getting time out, following is my code: 我正在尝试从网站获取简单的gzip编码的html响应,并且该响应持续超时,以下是我的代码:
HttpWebRequest httpClient = (HttpWebRequest)WebRequest.Create(url);
httpClient.Method = "GET";
httpClient.Accept = "text/html, application/xhtml+xml, */*";
httpClient.Headers.Add("Accept-Encoding: gzip, deflate");
httpClient.Headers.Add("Accept-Language: en-US");
httpClient.Headers.Add("DNT: 1");
httpClient.ProtocolVersion = HttpVersion.Version10;
httpClient.KeepAlive = true;
httpClient.Timeout = System.Threading.Timeout.Infinite;
httpClient.CookieContainer = cookieJar;
String responseAsText;
using (HttpWebResponse response = (HttpWebResponse)httpClient.GetResponse())
{
System.IO.StreamReader sr;
if (response.ContentEncoding.Equals("gzip"))
{
sr = new StreamReader(new GZipStream(response.GetResponseStream(), CompressionMode.Decompress));
}
else
{
sr = new System.IO.StreamReader(response.GetResponseStream());
}
responseAsText = sr.ReadToEnd();
}
The url I'm trying to hit is "https client.schwab.com/Login/SignOn/CustomerCenterLogin.aspx" 我要输入的网址是“ https client.schwab.com/Login/SignOn/CustomerCenterLogin.aspx”
This works perfectly fine in the Browser, using Fiddler I viewed the browser's Request header and since its Transfer-Encoding: chunked
, I have used HttpVersion10
这在浏览器中工作得很好,使用Fiddler,我查看了浏览器的Request标头,并且由于它的
Transfer-Encoding: chunked
HttpVersion10
,我使用了HttpVersion10
I have also tried setting httpClient.Timeout = System.Threading.Timeout.Infinite
, but it never gets back with a response, however in browser the response gets in few seconds. 我也尝试过设置
httpClient.Timeout = System.Threading.Timeout.Infinite
,但是它永远不会返回响应,但是在浏览器中响应会在几秒钟内得到。
Please someone help me in achieving this. 请有人帮助我实现这一目标。
可能您可以尝试设置代理属性,这样它就不会将您识别为漫游器。
I think Nero has answered your question .. 我认为Nero回答了您的问题..
Try adding these Lines in your code.. 尝试在代码中添加这些行。
request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.