HttpWebRequest's Timeout and ReadWriteTimeout — What do these mean for the underlying TCP connection?

前端 未结 4 1047
醉酒成梦
醉酒成梦 2021-02-03 22:19

I believe I understand the practical differences between HttpWebRequest.Timeout and HttpWebRequest.ReadWriteTimeout. However, I\'m seeking further<

4条回答
  •  情书的邮戳
    2021-02-03 23:19

    This problem has been debated on another question, see Adjusting HttpWebRequest Connection Timeout in C#. The discussion made my head spin, so I'll offer my summary.

    Although, MSDN explains that the HttpWebRequest.Timeout Property applies to HttpWebRequest.GetResponse and HttpWebRequest.GetRequestStream calls, the description is a bit confusing.

    Jim Mischel is more helpful: Timeout "is the time for the server to respond to a request, not the amount of time to wait for the server to respond and send down all of the data." Thus, Timeout covers establishing a working connection. For large payloads, this does not imply that the request/reply is complete.

    ReadWriteTimeout applies to Read or Write operations to streams that transmit over the connection. E.g. when you Write to the stream returned by GetRequestStream. The connection is already established, but there is a risk that it will break. E.g. the network connection goes down.

    The Jim Mischel link has some very good advice on what values to set these timeout. I.e. the default for ReadWriteTimeout is too long.

提交回复
热议问题