今天我正在开发一个Java RMI服务器(也是客户端),它从页面获取信息并返回我想要的内容。我把代码放在这里。问题是,有时我传递给方法的URL会抛出一个IOException,它说明给定的url会导致503 HTTP错误。如果它总是这样,可能会很容易,但事情有时会出现。 我有这种方法结构,因为我解析的页面来自天气公司,我希望来自多个城市的信息,不仅仅是一个,所以一些城市在第一次机会时完美地工作,而其他一些城市则失败。有什么建议么?HTTP中的页面解析期间的HTTP错误503
public ArrayList<Medidas> parse(String url){
medidas = new ArrayList<Medidas>();
int v=0;
String sourceLine;
String content = "";
try{
// The URL address of the page to open.
URL address = new URL(url);
// Open the address and create a BufferedReader with the source code.
InputStreamReader pageInput = new InputStreamReader(address.openStream());
BufferedReader source = new BufferedReader(pageInput);
// Append each new HTML line into one string. Add a tab character.
while ((sourceLine = source.readLine()) != null){
if(sourceLine.contains("<tbody>")) v=1;
else if (sourceLine.contains("</tbody>"))
break;
else if(v==1)
content += sourceLine + "\n";
}
........................
........................ NOW THE PARSING CODE, NOT IMPORTANT
}
完成,这不是我的错。今天一切正常,我认为页面服务器已被修复。谢谢 – antonbalboa 2013-03-28 15:16:02