我如何无限期地等待C#中的WebRequest的答案
我正在将网络重新发布到一个响应非常缓慢的页面上。响应的大小和持续时间各不相同。有时需要超过5分钟才能完成答复。浏览器成功地等待了答案,但是我的WebRequest事先以错误的504打破了答案。 我该如何防止这种情况。 在这里,我的代码(我将所有超时都设置为-1,没有任何成功)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(req_url));
request.Accept = "text/html";
request.UserAgent = "Mozilla / 4.0(compatible; MSIE 6.0; " + "Windows NT 5.2; .NET CLR 1.0.3705;)";
request.Timeout = -1;
request.KeepAlive = true;
request.ReadWriteTimeout = -1;
request.AllowReadStreamBuffering = false;
request.AllowWriteStreamBuffering = false;
request.ReadWriteTimeout = -1;
request.ContinueTimeout = -1;
,这里是一个示例查询:
http ://www.bml3.nrw.de/service/bml? 475 %2C364538.615320737%2C5704402.64151475,EPSG:25832
I'm making a webrequest to a page that is responding very slowly. the size and duration of the response varies. sometimes it takes more than 5 minutes to finish reply. the browser waits successfully for the answer, but my webrequest breaks off with error 504 beforehand.
How can I prevent this.
here my code (I set all timeouts to -1, without any success)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri(req_url));
request.Accept = "text/html";
request.UserAgent = "Mozilla / 4.0(compatible; MSIE 6.0; " + "Windows NT 5.2; .NET CLR 1.0.3705;)";
request.Timeout = -1;
request.KeepAlive = true;
request.ReadWriteTimeout = -1;
request.AllowReadStreamBuffering = false;
request.AllowWriteStreamBuffering = false;
request.ReadWriteTimeout = -1;
request.ContinueTimeout = -1;
and here is an example query:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在web.config
&lt; httpruntime executionTime ut =“ 1000” /&gt; < /code>
web.config:
httpwebrequest.getResponse( )
是一次性的,应用used()关闭来包装。这可能是您的根本问题90%。You can specify the request timeout (in seconds) in the web.config
<httpRuntime executionTimeout="1000" />
web.config:
httpWebRequest.GetResponse()
is disposable and should be wrapped with using() closures. This is 90% likely to be your underlying problem.