我有一个这样的WebRequest,但是我用它检索大文件并给出大文件的超时时间,但是我不能将超时时间延长到无限制或至少10分钟,有人知道怎么做吗?
HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri);
httpWebRequest.CookieContainer = user.cookies;
httpWebRequest.Host = uri.Host;
httpWebRequest.Method = WebRequestMethods.Http.Get;
httpWebRequest.Accept = user.post_headers.FirstOrDefault(x => x.Key == 8).Value;
httpWebRequest.UserAgent = user.post_headers.FirstOrDefault(x => x.Key == 4).Value;
httpWebRequest.AllowWriteStreamBuffering = true;
httpWebRequest.ProtocolVersion = HttpVersion.Version11;
httpWebRequest.AllowAutoRedirect = true;
httpWebRequest.KeepAlive = true;
HttpWebResponse response_posts = (HttpWebResponse)httpWebRequest.GetResponse();
using (httpWebReponse = (HttpWebResponse)httpWebRequest.GetResponse())
{
发布于 2016-04-06 21:43:50
您应该能够在HttpWebRequest
对象上设置Timeout
属性
HttpWebRequest.Timeout Property
编辑1:
实际上,Timeout属性可能会对初始连接产生影响,并且没有规定在GetResponse()中接收信息的超时时间。
这是服务器响应请求的时间,而不是等待服务器响应并向下发送所有数据的时间
尽管这与MSDN的状态相冲突;
超时适用于整个请求和响应,而不是分别适用于GetRequestStream和GetResponse方法调用。
因此,您还可以尝试设置ReadWriteTimeout
属性。
发布于 2016-04-06 21:46:46
这是另一种解决方案
request.Headers["timeout"] = "300"; // in seconds
https://stackoverflow.com/questions/36452857
复制相似问题