rlc*_*rlc 15 java http urlconnection
我正在用Java解决这个问题.我想从URL获取一些HTML信息.这段代码工作了很长时间,但突然间,它停止了工作.
当我使用浏览器访问此URL时,它会打开没有问题.
代码:
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();
Run Code Online (Sandbox Code Playgroud)
例外情况:
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)
Run Code Online (Sandbox Code Playgroud)
怎么了?主人挡住了我吗?
Bal*_*usC 26
HTTP状态代码500通常意味着Web服务器代码已崩溃.您需要事先确定状态代码HttpURLConnection#getResponseCode(),如果有错误,请先阅读HttpURLConnection#getErrorStream().它可能包含有关问题的信息.
如果主机阻止了您,您宁愿获得像401或403这样的4nn状态代码.
| 归档时间: |
|
| 查看次数: |
175526 次 |
| 最近记录: |