gpt4 book ai didi

java - 服务器返回 HTTP 响应代码 : 503 for URL

转载 作者:搜寻专家 更新时间:2023-11-01 02:42:30 25 4
gpt4 key购买 nike

当我多次调用亚马逊产品时出现“线程“主”java.io.IOException 中的异常:服务器返回 HTTP 响应代码:URL 503”错误广告 API。

是服务重载的原因吗?一种可能的解决方案是使用 Thread.Sleep(milliseconds) 方法。

但是还有其他更复杂的解决方案吗?比如代理之类的?

这是用于建立连接的代码:

URL amazon = new URL(url);
URLConnection yc = amazon.openConnection();
BufferedReader in = new BufferedReader(
new InputStreamReader(
yc.getInputStream()));

我正在使用 Java!

最佳答案

来自 http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html ,它定义了这些状态代码:

10.5.4 503 Service Unavailable

The server is currently unable to handle the request due to a temporary overloading or maintenance of the server. The implication is that this is a temporary condition which will be alleviated after some delay. If known, the length of the delay MAY be indicated in a Retry-After header. If no Retry-After is given, the client SHOULD handle the response as it would for a 500 response.
Note: The existence of the 503 status code does not imply that a server must use it when becoming overloaded. Some servers may wish to simply refuse the connection.

是的,服务器过载是一个可能的原因。要弄清楚如何处理这个问题,您可能需要与运营该服务的人讨论,以了解他们可以容忍什么。然后,如果您在 SO 上搜索“throttle web requests”,您会发现很多关于如何在了解您的要求后实现限制的讨论。

编辑

现在我看到您在谈论亚马逊广告 API,快速搜索让我进入了这个页面:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html

该页面上的效率指南非常清楚地说明了什么会触发您的问题,以及可接受的请求率。

关于java - 服务器返回 HTTP 响应代码 : 503 for URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30492370/

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