1
好吧,我在我的智慧结束。我一直在尝试〜小时〜阅读下面的URL到Java字符串,我不能为我的生活做到这一点。我尝试了一种bajillion不同的方法(所有这些方法都适用于其他网页!)我已经在网上找到了,我正要失去理智!请帮我把这个网页的内容以Java字符串〜:(阅读SHOUTcast的7.html与Java
http://molestia.ponify.me:8062/7.html
答:
URL url = new URL("http://molestia.ponify.me:8062/7.html");
URLConnection con = url.openConnection();
con.setRequestProperty("User-Agent", "Mozilla/5.0"); // This bugger right here saved the day!
Reader r = new InputStreamReader(con.getInputStream());
StringBuilder buf = new StringBuilder();
while (true) {
int ch = r.read();
if (ch < 0)
break;
buf.append((char) ch);
}
String str = buf.toString();
Log.d("HTML", str);
你是英雄! <3我将在我的主帖中添加我用来解决这个问题的代码片段。 – Karai17 2012-02-22 17:37:03