简体   繁体   English

java.io.IOException:服务器返回HTTP响应代码:500

[英]java.io.IOException: Server returned HTTP response code: 500

I'm facing this problem with Java. 我正在用Java解决这个问题。 I want to get some HTML informations from a URL. 我想从URL获取一些HTML信息。 This code was working for so long, but suddenly, it stopped working. 这段代码工作了很长时间,但突然间,它停止了工作。

When I access this URL using the browser, it opens with no problem. 当我使用浏览器访问此URL时,它会打开没有问题。

The code: 代码:

URL site = new URL(this.url);
java.net.URLConnection yc = site.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
String inputLine;
String objetivo = "<td height=\"28\" colspan=\"2\"";
while ((inputLine = in.readLine()) != null && !inputLine.contains(objetivo)) {
}
inputLine = in.readLine();

The Exception: 例外情况:

java.io.IOException: Server returned HTTP response code: 500 for URL: http://www.myurl.com
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
    at Sites.websites.Site1.getData(Site1.java:53)
    at util.Util.lerArquivo(Util.java:278)
    at util.Util.main(Util.java:983)

What's wrong? 怎么了? Did the host block me? 主人挡住了我吗?

HTTP status code 500 usually means that the webserver code has crashed. HTTP状态代码500通常意味着Web服务器代码已崩溃。 You need to determine the status code beforehand using HttpURLConnection#getResponseCode() and in case of errors, read the HttpURLConnection#getErrorStream() instead. 您需要事先使用HttpURLConnection#getResponseCode()确定状态代码,如果有错误,请改为读取HttpURLConnection#getErrorStream() It may namely contain information about the problem. 它可能包含有关问题的信息。

If the host has blocked you, you would rather have gotten a 4nn status code like 401 or 403. 如果主机阻止了您,您宁愿获得像401或403这样的4nn状态代码。

See also: 也可以看看:

This Status Code 500 is an Internal Server Error. 此状态码500是内部服务器错误。 This code indicates that a part of the server (for example, a CGI program) has crashed or encountered a configuration error. 此代码表示服务器的一部分(例如,CGI程序)已崩溃或遇到配置错误。

i think the problem does'nt lie on your side, but rather on the side of the Http server. 我认为问题并不在于你,而在于Http服务器。 the resources you used to access may have been moved or get corrupted, or its configuration just may have altered or spoiled 您用于访问的资源可能已被移动或损坏,或者其配置可能已被更改或损坏

I have encountered the same problem and found out the solution. 我遇到了同样的问题并找到了解决方案。

You may look within the first server response and see if the server sent you a cookie. 您可以查看第一个服务器响应,看看服务器是否向您发送了cookie。

To check if the server sent you a cookie, you can use HttpURLConnection#getHeaderFields() and look for headers named "Set-Cookie". 要检查服务器是否向您发送了cookie,您可以使用HttpURLConnection#getHeaderFields()并查找名为“Set-Cookie”的标头。

If existing, here's the solution for your problem. 如果存在, 这里是您的问题的解决方案。 100% Working for this case! 100%为此案件工作!

+1 if it worked for you. +1,如果它适合你。

I had this problem ie works fine when pasted into browser but 505s when done through java. 我有这个问题,即粘贴到浏览器时工作正常,但通过java完成505s。 It was simply the spaces that needed to be escaped/encoded. 它只是需要转义/编码的空间。

The problem must be with the parameters you are passing(You must be passing blank parameters). 问题必须与您传递的参数有关(您必须传递空白参数)。 For example : http://www.myurl.com?id=5&name= Check if you are handling this at the server you are calling. 例如: http//www.myurl.com?id = 5& name =检查您是否在要呼叫的服务器上处理此问题。

将内容类型更改为“application / x-www-form-urlencoded”,我解决了问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 java.io.IOException:服务器在上传JSON对象时返回了HTTP响应代码:URL为500 - java.io.IOException: Server returned HTTP response code: 500 for URL while uploading JSON object java.io.IOException:服务器针对URL:“ SoapEndPoint url”返回了HTTP响应代码:500 - java.io.IOException: Server returned HTTP response code: 500 for URL:“SoapEndPoint url” java.io.IOException:服务器返回 HTTP 响应代码:500 用于 URL:https:// - java.io.IOException: Server returned HTTP response code: 500 for URL: https:// java.io.IOException:服务器返回的HTTP响应代码:URL的500 - java.io.IOException: Server returned HTTP response code: 500 for URL 错误是 java.io.IOException:服务器返回 HTTP 响应代码:URL 为 500:调用 weservice 时 - Error is java.io.IOException: Server returned HTTP response code: 500 for URL: while invoking weservice java.io.IOException:服务器返回HTTP响应代码:502 - java.io.IOException: Server returned HTTP response code: 502 java.io.IOException:服务器返回的HTTP响应代码:500(用于URL:https:// hostname:port / xxx.do) - java.io.IOException: Server returned HTTP response code: 500 for URL: https://hostname:port/xxx.do Java Http(s)URLConnection java.io.IOException:服务器返回 HTTP 响应代码:403 - Java Http(s)URLConnection java.io.IOException: Server returned HTTP response code: 403 在Java代码中获取“ java.io.IOException:服务器返回的HTTP响应代码:URL的403:” - Getting “java.io.IOException: Server returned HTTP response code: 403 for URL: ” in java code 服务器返回 java.io.IOException:服务器返回 HTTP 响应代码:URL 为 400 - server returns java.io.IOException: Server returned HTTP response code: 400 for URL
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM