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

标签 java api url http-status-code-503

当我多次调用亚马逊产品时出现“线程“主”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/

相关文章:

java - 如何在java中的JTable的特定行和列上删除Jlist项?

api - 如何根据日期范围在 Stripe 中获取费用(交易)详细信息

apache - 设置子域: ex -- "www.example.com" to store images at "images.example.com"

R - POST 的 JSON 结构

api - 从 Google API 获取点击次数

javascript - jquery 检查 URL 是否已经有查询字符串

c# - 在 .NET 中创建 Uri 会自动对传递的字符串中的所有参数进行 urldecode

java - 如何使用接口(interface)作为参数?

java - 迭代器中的无限循环

java - RecyclerView OnClick 带到另一个 Fragment