简体   繁体   English

System.Net.WebException:操作在 System.Net.HttpWebRequest.GetResponse 超时

[英]System.Net.WebException: The operation has timed out at System.Net.HttpWebRequest.GetResponse

I'm trying to navigate some webpages but sometimes I receive "the operation has timed out" error.. sometimes it works days without any error.. After received the error, if I try to navigate from WebBrowser, it navigate without any problem, but if I want to navigate with webrequest again, I get this error again...我正在尝试浏览一些网页,但有时我会收到“操作已超时”错误.. 有时它可以正常工作几天而没有任何错误.. 收到错误后,如果我尝试从 WebBrowser 导航,它导航没有任何问题,但是如果我想再次使用 webrequest 导航,我会再次收到此错误...

I have tryied to set ReadWriteTimeout and Timeout property from 2-3 minutes, up to infinite.. still without any luck :(我已经尝试将 ReadWriteTimeout 和 Timeout 属性设置为 2-3 分钟,直到无限……仍然没有任何运气:(

here is my code:这是我的代码:

static void setHeaders(ref WebRequest reqPOST, string sUrl)
{
reqPOST = System.Net.WebRequest.Create(sUrl);
reqPOST.Method = "GET";
((HttpWebRequest)reqPOST).UserAgent = "dummie useragent";
((HttpWebRequest)reqPOST).Accept = "*/*";
((HttpWebRequest)reqPOST).KeepAlive = true;
((HttpWebRequest)reqPOST).Timeout = Timeout.Infinite;
reqPOST.Headers.Add("Accept-Language", "en-US");
reqPOST.Headers.Add("Accept-Encoding", "gzip, deflate");
}

static void getResponse(ref WebRequest reqPOST, ref WebResponse result, ref StreamReader reader, ref string responseFromServer)
{
result = reqPOST.GetResponse();
if (result.Headers.Get("Content-Encoding") != null && result.Headers.Get("Content-Encoding").ToLower() == "gzip")
    reader = new System.IO.StreamReader(new GZipStream(result.GetResponseStream(), CompressionMode.Decompress));
else
    reader = new System.IO.StreamReader(result.GetResponseStream());
responseFromServer = reader.ReadToEnd();
}
setHeaders(ref reqPOST, "somewebsite");
getResponse(ref reqPOST, ref result, ref reader, ref responseFromServer);
reader.Close();
result.Close();

any ideas please ?有什么想法吗? thank you.谢谢你。

你应该尝试添加

reqPOST.Timeout = 1000000; // Increase timeout

暂无
暂无

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

相关问题 从亚马逊 s3 读取图像和视频时,在 System.Net.HttpWebRequest.GetResponse() 处获取 WebException“操作已超时” - Getting WebException “The operation has timed out” at System.Net.HttpWebRequest.GetResponse() when reading images and video from amazon s3 向主机发送大量请求时 System.Net.HttpWebRequest.GetResponse() 的操作超时 - The operation has timed out at System.Net.HttpWebRequest.GetResponse() while sending large number of requests to a host System.Net.WebException:远程服务器返回错误:(401)未经授权。 在System.Net.HttpWebRequest.GetResponse() - System.Net.WebException: The remote server returned an error: (401) Unauthorized. at System.Net.HttpWebRequest.GetResponse() System.Net.WebException:操作已在HttpWebResponse上超时 - System.Net.WebException: The operation has timed out on HttpWebResponse System.Net.WebException:操作已超时 - System.Net.WebException: The operation has timed out System.Net.WebResponse 抛出“System.Net.WebException: The operation has timed out”但已连接到 Web 服务器 - System.Net.WebResponse throwing “System.Net.WebException: The operation has timed out” but connection to web server was made 处理未处理的异常:System.Net.WebException:请求超时? - Handle Unhandled Exception: System.Net.WebException: The request timed out? System.Net.HttpWebRequest.GetResponse()中的错误“ResponceSystem.Net.WebException:请求已中止:无法创建SSL / TLS安全通道” - Error in System.Net.HttpWebRequest.GetResponse() “ResponceSystem.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel” HttpWebRequest .GetResponse 抛出 WebException '操作已超时' - HttpWebRequest .GetResponse throws WebException 'The operation has timed out' HttpWebRequest引发System.Net.WebException Section = ResponseStatusLine - HttpWebRequest throws System.Net.WebException Section=ResponseStatusLine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM