java - 何时使用请求超时和网关超时

标签 java spring resttemplate http-status-codes

我正在为第三方 API 编写包装器。

如果我在特定时间内没有收到响应,我将抛出网关超时异常。

但是我可以看到除了HttpStatus.GATEWAY_TIMEOUT之外还有一个HttpStatus.REQUEST_TIMEOUT

我不知道该用哪个,什么时候用。

感谢任何帮助。

最佳答案

一旦您的服务器充当上游服务器的网关或代理,您应该使用504以指示连接已超时。看看这个状态码是怎么定义的:

6.6.5. 504 Gateway Timeout

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状态代码具有完全不同的含义,表示服务器想要关闭与客户端未使用的连接:

6.5.7. 408 Request Timeout

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, since 408 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/

相关文章:

java - Spring Remoting 序列化和反序列化

angularjs - 在单个 http 请求中使用与每个文件相关的元数据上传多文件

java - spring boot web绑定(bind)时如何拦截错误信息?

java - 使用 apache poi 从 excel 读取日期格式,无论系统日期格式如何

java - UnsatisfiedDependencyException 在 SpringBoot 中使用 @DataJpaTest

java - 带有标题 : webservice can't find my header parameters 的 Spring RestTemplate postForObject

spring - 如何强制 RestTemplate 使用 UTF-8 编码发送 multipart/form-data

java - 亚马逊 sqs 抛出异常连接重置

java - 如何使用picasso显示来自URI的图像?图像不显示

java - 在 if-else 中初始化字符串变量