gpt4 book ai didi

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

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:01:36 27 4
gpt4 key购买 nike

我正在为第三方 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 responsefrom an upstream server it needed to access in order to complete therequest.

408状态代码具有完全不同的含义,表示服务器想要关闭与客户端未使用的连接:

6.5.7. 408 Request Timeout

The 408 (Request Timeout) status code indicates that the server didnot receive a complete request message within the time that it wasprepared to wait. A server SHOULD send the "close" connection optionin the response, since 408 implies thatthe server has decided to close the connection rather than continuewaiting. If the client has an outstanding request in transit, theclient MAY repeat that request on a new connection.

关于java - 何时使用请求超时和网关超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50448804/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com