Java 服务器返回 HTTP 响应代码:URL 503

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30492370/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 09:43:15  来源:igfitidea点击:

Server returned HTTP response code: 503 for URL

javaapiurlhttp-status-code-503

提问by DataMiningEnthusiast

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.

获得“异常线程‘main’产生java.io.IOException:网址503:服务器返回的HTTP响应代码错误,当我做出亚马逊产品广告API多次调用”。

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

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

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!

我正在使用Java!

采纳答案by Andy Lowry

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

来自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.

10.5.4 503 服务不可用

由于服务器暂时过载或维护,服务器当前无法处理请求。这意味着这是一个暂时的情况,将在一些延迟后得到缓解。如果已知,延迟的长度可以在 Retry-After 头中指示。如果没有给出 Retry-After ,客户端应该像处理 500 响应一样处理响应。
注意:503 状态代码的存在并不意味着服务器在过载时必须使用它。一些服务器可能希望简单地拒绝连接。

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.

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

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

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

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

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

回答by K139

HTTP 503 means Requested Service is Unavailable.

HTTP 503 表示请求的服务不可用。

It might be due to,

可能是由于,

1) Server might be busy

1) 服务器可能很忙

2) Server might be down for maintenance

2) 服务器可能因维护而停机

If you are accessing a serviceand getting this error, then try to contact the serviceowner to find out what's going on.

如果您正在访问 aservice并收到此错误,请尝试联系service所有者以了解发生了什么。

If you are the owner of the service, then check the errors in the log to find out the problem.

如果您是该服务的所有者,请检查日志中的错误以找出问题所在。

If you are just making lot's of connections to the service from client class, and getting this error, then you need to think about why you need to create so many connections.

如果您只是从客户端类与服务建立大量连接,并收到此错误,那么您需要考虑为什么需要创建这么多连接。