HttpWebRequest.ReadWriteTimeout 属性


获取或设置写入或读取流时的超时(以毫秒为单位)。Gets or sets a time-out in milliseconds when writing to or reading from a stream.

 property int ReadWriteTimeout { int get(); void set(int value); };
public int ReadWriteTimeout { get; set; }
member this.ReadWriteTimeout : int with get, set
Public Property ReadWriteTimeout As Integer


写入或读取超时之前的毫秒数。默认值为300000毫秒(5分钟)。The number of milliseconds before the writing or reading times out. The default value is 300,000 milliseconds (5 minutes).


已发送请求。The request has already been sent.

为 Set 操作指定的值小于等于零,并且不等于 InfiniteThe value specified for a set operation is less than or equal to zero and is not equal to Infinite


下面的代码示例演示如何设置 ReadWriteTimeout 属性。The following code example shows how to set the ReadWriteTimeout property.

HttpWebRequest myReq =
myReq.ReadWriteTimeout = 100000;


写入 GetRequestStream 方法返回的流或从 GetResponseStream 方法返回的流中读取时,将使用 ReadWriteTimeout 属性。The ReadWriteTimeout property is used when writing to the stream returned by the GetRequestStream method or reading from the stream returned by the GetResponseStream method.

具体而言,ReadWriteTimeout 属性控制 Read 方法的超时,此方法用于读取 GetResponseStream 方法返回的流,并用于读取用于写入 GetRequestStream 方法返回的流的 Write 方法。Specifically, the ReadWriteTimeout property controls the time-out for the Read method, which is used to read the stream returned by the GetResponseStream method, and for the Write method, which is used to write to the stream returned by the GetRequestStream method.

若要指定等待请求完成的时间量,请使用 Timeout 属性。To specify the amount of time to wait for the request to complete, use the Timeout property.