C# GET-Webrequest超时

C# GET-Webrequest超时,c#,webrequest,httpwebresponse,C#,Webrequest,Httpwebresponse,我有一个WebRequest,但是我用它检索大文件,并给大文件超时,但是我不能将超时延长到无限或至少10分钟,有人知道如何做吗 HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(uri); httpWebRequest.CookieContainer = user.cookies; httpWebRequest.Host = uri.Host; httpWebRequest.Method = WebRequest

我有一个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())
{

您应该能够在
HttpWebRequest
对象上设置
Timeout
属性

# 编辑1:

实际上,Timeout属性可能会对初始连接产生影响,并且不会指定GetResponse()中接收信息的超时

这是服务器响应请求的时间,而不是等待服务器响应并发送所有数据的时间

尽管这与MSDN的声明相冲突

超时应用于整个请求和响应,而不是单独应用于GetRequestStream和GetResponse方法调用

因此,您还可以尝试设置
ReadWriteTimeout
属性


这是另一种解决方案

request.Headers["timeout"] = "300"; // in seconds 

是的,我已经找不到这一点,如果你在几分钟内发送,它只需等待几分钟即可执行。)我将尝试ReadWriteTimeOut