Android 台灣中文網
標題:
讀取XML抓不到資料
[打印本頁]
作者:
sfzvzfbv
時間:
2016-1-22 17:45
標題:
讀取XML抓不到資料
我要抓取政府的OpenData資料庫的XML,但是始終抓不到資料,不知道是不是連線的程式碼有問題,請教各位前輩。
private static InputStream connect() {
HttpURLConnection urlConnection = null;
InputStream inputStream = null;
try {
URL url = new URL("http://opendata2.epa.gov.tw/AQX.xml");
urlConnection = (HttpURLConnection) url.openConnection();
urlConnection.setReadTimeout(10000);
urlConnection.setConnectTimeout(15000);
urlConnection.setRequestMethod("GET");
urlConnection.connect();
inputStream = new BufferedInputStream(urlConnection.getInputStream());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Exception e) {
e.getMessage();
} finally {
assert urlConnection != null;
urlConnection.disconnect();
}
return inputStream;
}
複製代碼
作者:
whl
時間:
2016-1-23 20:42
可能的問題點太多了,為何不貼 log 來看?
作者:
sfzvzfbv
時間:
2016-1-23 23:31
whl 發表於 2016-1-23 20:42
可能的問題點太多了,為何不貼 log 來看?
程式沒有出現任何錯誤,只是抓不到網路資料,上面是連線到網路的程式碼,我只是想問上面的程式碼有沒有錯誤而已。
作者:
NekoRin
時間:
2016-2-7 20:44
URL的位址是否正確??
作者:
x3093410155
時間:
2016-3-14 23:38
本帖最後由 x3093410155 於 2016-3-14 23:40 編輯
我大概知道你在GET網頁 之後的代碼就不知道了 因為我不是C#的程序員
你是要把資料全部都套出來之後顯示在軟件上面嗎?
如果是這樣就要用正則匹配資料
歡迎光臨 Android 台灣中文網 (https://apk.tw/)
Powered by Discuz! X3.1