Code: Alles auswählen
public static String getUrlContent(String strUrl) throws MalformedURLException,
IOException {
try {
Thread.sleep(500);
} catch (InterruptedException e) {
}
String retval = "";
String line = null;
int versuche = 1;
BufferedReader reader = null;
while (versuche <= 20) {
System.out.println("getUrlContent:"+strUrl);
URL url = new URL(strUrl);
HttpURLConnection con = (HttpURLConnection) url.openConnection();
InputStream in = con.getInputStream();
InputStreamReader inReader = new InputStreamReader(in);
reader = new BufferedReader(inReader);
if (reader.ready()) {
break;
}
versuche++;
try {
System.out.println("PAUSE, Try Nr. "+versuche);
Thread.sleep(4000);
} catch (InterruptedException e) {
}
}
StringBuffer content = new StringBuffer();
line = reader.readLine();
while (line != null) {
content.append(line + "\n");
line = reader.readLine();
}
retval = content.toString();
return retval;
}