System.Web.HttpException:请求超时错误?
我有一个发出网络请求的线程类。在20-30个url请求之后,它抛出异常:System.Web.HttpException:请求超时。 我的代码位于抛出异常的下面:
httpReq.AllowAutoRedirect = false;
httpReq.KeepAlive = false;
httpReq.Headers.Add("Location", "");
httpReq.Timeout = this.HttpRequestTimeout;
httpRes = (HttpWebResponse)httpReq.GetResponse();
在最后一行:httpRes = (HttpWebResponse)httpReq.GetResponse(); 它正在抛出异常。 “远程服务器返回错误:(403) 禁止。”
我正在使用会话通过请求标头设置一些值。
I have a thread class which makes a web request. After 20-30 urls request, its throwing exception: System.Web.HttpException: Request timed out.
My code is below where it is throwing exception:
httpReq.AllowAutoRedirect = false;
httpReq.KeepAlive = false;
httpReq.Headers.Add("Location", "");
httpReq.Timeout = this.HttpRequestTimeout;
httpRes = (HttpWebResponse)httpReq.GetResponse();
In last line : httpRes = (HttpWebResponse)httpReq.GetResponse();
it is throwing exception.
"The remote server returned an error: (403) Forbidden."
I am using session for setting some values with the request header.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得到了答案。使用响应对象后,我没有使用 httpRes.close() 方法。这就是为什么在 80-90 请求之后它返回:“远程服务器返回错误:(403) Forbidden”。
I got the answer. I was not using httpRes.close() method after using response object. That's why after 80-90 request it was returning : "The remote server returned an error: (403) Forbidden ".