The operation has timed out & 504 Gateway Timeout

转自:

http://stackoverflow.com/questions/18665756/difference-between-operation-has-time-out-and-504-gateway-timeout

The operation has timed out is a client error. It is usually caused by various *Timeout properties ofWebRequest (and its descendants): TimeoutContinueTimeoutReadWriteTimeout. If the server you sent request to does not respond within the timeout you set, you get TimeoutException.

To avoid this error, you can increase timeouts. However, they are quite big by default, so increasing is unlikely to help. You can try several times. If it doesn't help, the server is probably down.

504 Gateway Timeout is a server error. It is usually caused by errors in or overloading of the server infrastructure you sent requests to. It is black box for you.

You can't do anything about this error, only server administrators can resolve that. If the error is caused by overloading, you can try requesting several times, but doing this too often will do more harm than good, obviously.

In general, if you don't get an HTTP code, it's an exception from .NET. If you do get an HTTP code, you can look at the first digit:

2** OK
3** Redirection
4** Client error
5** Server error

备忘:

The operation has timed out是发生在客户端的错误,

通常是因为WebRequest的Timeout ,ContinueTimeout, ReadWriteTimeout等属性的设置引发.

如果服务器在你设定的时间内没有响应你发送的请求,就会引发这个超时异常.

为了避免这种异常,你可以增加超时时间,但是默认的超时时间相当长,所以增加超时时间有时也会没有用.

你也可以增加retry次数,如果也没用,有可能就是服务器宕机了.

504 Gateway Timeout是发生在服务器的错误,

它通常因为你请求的服务器基础设施超载引起,这对于你来说,是黑盒,是不可见的.

你无法做任何事情,只有等服务器管理员去解决它,如果这个错误时因为超载引起,你可以retry,但这通常不是一个好主意.

一般情况下,你得到的是得到.net抛出的异常,而不是HTTP状态码.如果你得到了HTTP状态码,你可以先检查下状态码.

原文地址:https://www.cnblogs.com/iot1024/p/5013101.html