Android RSS无法从链接下载xml文件

时间:2013-05-22 06:54:52

标签: android httpwebrequest rss-reader

我已经知道如何从本地存储中读取xml文件。但现在我想从雅虎获取消息! [link:http://hk.news.yahoo.com/rss/hong-kong]

我使用下面的代码但它返回错误,出了什么问题?!?!

String source = "http://hk.news.yahoo.com/rss/hong-kong";
URL url = new URL(source);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setRequestMethod("GET");
urlConnection.connect();

InputStreamReader in = new InputStreamReader(urlConnection.getInputStream());
BufferedReader br = new BufferedReader(in);
String result = br.readLine();
Log.i(tag, "GET success: " + result);

br.close();
in.close();

错误日志是:

05-22 14:34:25.696:E / RSS(24465):java.net.ConnectException:无法连接到hk.news.yahoo.com/2406:2000:ac:8::c:9102(端口80):连接失败:EHOSTUNREACH(无主机路由)

谢谢!

1 个答案:

答案 0 :(得分:0)

检查android Androidmanifest.xml中的应用程序互联网权限。

 <uses-permission android:name="android.permission.INTERNET" />

由于