服务器返回 HTTP 响应代码:URL 503 [英] Server returned HTTP response code: 503 for URL

查看:201
本文介绍了服务器返回 HTTP 响应代码:URL 503的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

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

我正在使用 Java!

解决方案

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

<块引用>

10.5.4 503 服务不可用

由于服务器暂时过载或维护,服务器当前无法处理请求.这意味着这是一个暂时的情况,将在一些延迟后得到缓解.如果已知,延迟的长度可以在 Retry-After 头中指示.如果没有给出 Retry-After ,客户端应该像处理 500 响应一样处理响应.

注意:503 状态代码的存在并不意味着服务器在过载时必须使用它.一些服务器可能希望简单地拒绝连接.

所以是的,服务器过载是一个可能的原因.要弄清楚如何处理这个问题,您可能想与运营该服务的任何人讨论,以了解他们可以容忍什么.然后,如果您在 SO 上搜索throttle web requests",您会在了解您的需求后找到许多关于如何实施节流的讨论.

编辑

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

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

Getting "Exception in thread "main" java.io.IOException: Server returned HTTP response code: 503 for URL" error when I make multiple calls to Amazon Product Advertising API.

Is the reason overloading of the service? One Possible solution is to use Thread.Sleep(milliseconds) method.

But is there any other more sophisticated solution? Like proxies or something?

Here is the code used to make the connection:

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

I am using Java!

解决方案

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html, which defines these status codes:

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 yes, server overload is a likely cause. To figure out how to deal with this you probably want to discuss it with whoever operates the service, to understand what they can tolerate. Then, if you search for "throttle web requests" on SO, you'll find a number of discussions of how to implement throttling once you know your requirement.

Edit

Now that I see you're talking about Amazon Advertising API, a quick search got me to this page: http://docs.aws.amazon.com/AWSECommerceService/latest/DG/TroubleshootingApplications.html

The Efficiency Guidelines on that page pretty clearly state what will trigger your problem, and the request rates that are acceptable.

这篇关于服务器返回 HTTP 响应代码:URL 503的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆