我正在为第三方 API 编写包装器。
如果我在特定时间内没有收到响应,我将抛出网关超时异常。
但是我可以看到除了HttpStatus.GATEWAY_TIMEOUT之外还有一个HttpStatus.REQUEST_TIMEOUT
我不知道该用哪个,什么时候用。
感谢任何帮助。
最佳答案
一旦您的服务器充当上游服务器的网关或代理,您应该使用504
以指示连接已超时。看看这个状态码是怎么定义的:
The
504
(Gateway Timeout) status code indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.
408
状态代码具有完全不同的含义,表示服务器想要关闭与客户端未使用的连接:
The
408
(Request Timeout) status code indicates that the server did not receive a complete request message within the time that it was prepared to wait. A server SHOULD send the "close" connection option in the response, since408
implies that the server has decided to close the connection rather than continue waiting. If the client has an outstanding request in transit, the client MAY repeat that request on a new connection.
关于java - 何时使用请求超时和网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50448804/