到底什么是使用的WebRequest当超时?WebRequest

2023-09-08 08:35:10 作者:橘色汽水

MSDN指出 WebRequest.Timeout 手段

的时间长度,以毫秒为单位,直到请求超时,或   值Timeout.Infinite以指示该请求没有时间   出去。

The length of time, in milliseconds, until the request times out, or the value Timeout.Infinite to indicate that the request does not time out.

到底什么构成了超时?那是时间的最高金额的第一个字节返回之前,班会等吗?它是时间整个请求完成的最高金额?它是什么东西?

What exactly constitutes a "Timeout"? Is that the maximum amount of time the class will wait before the first byte is returned? Is it the maximum amount of time for the entire request to complete? Is it something else?

我这么问是因为我使用的是修改Web客户端从下载相当大(〜1GB)文件源,有时打嗝,并采取多分钟到几个小时开始发送一个响应。我想,设置超时时间,这样成功的转移(即最多可能需要根据不同的连接质量20分钟)不会超时,但这样偶尔会打嗝理想超时快。

I'm asking because I'm using a modified WebClient to download rather large (~1GB) files from a source that sometimes hiccups and takes many minutes to hours to begin sending a response. I want to set the timeout so that successful transfers (that can take up to 20 minutes depending on the connection quality) do not time out, but so that the occasional hiccups will ideally timeout quickly.

推荐答案

在接受的答案Adjusting在C#中的HttpWebRequest连接超时导致我检查的 ReadWriteTimeout 财产,其中规定

The unaccepted answers for Adjusting HttpWebRequest Connection Timeout in C# lead me to examine the ReadWriteTimeout property, which states

具体而言,ReadWriteTimeout属性控制超时   Read方法,其用于读取由所述返回的流   GetResponseStream方法,以及用于写入方法,它是用来   写由GetRequestStream方法返回的数据流。

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.