Getting “线程“main”中出现异常 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!
From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html,它定义了这些状态代码:
10.5.4 503 服务不可用
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”,您会发现许多关于一旦您了解了需求就如何实现限制的讨论。
Edit
现在我看到您正在谈论亚马逊广告 API,快速搜索让我进入了此页面:http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html
The 效率指南该页面上非常清楚地说明什么会触发您的问题,以及可接受的请求率。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)