Android 台灣中文網

標題: 讀取XML抓不到資料 [打印本頁]

作者: sfzvzfbv    時間: 2016-1-22 17:45
標題: 讀取XML抓不到資料
我要抓取政府的OpenData資料庫的XML,但是始終抓不到資料,不知道是不是連線的程式碼有問題,請教各位前輩。

  1. private static InputStream connect() {
  2.         HttpURLConnection urlConnection = null;
  3.         InputStream inputStream = null;
  4.         try {
  5.             URL url = new URL("http://opendata2.epa.gov.tw/AQX.xml");
  6.             urlConnection = (HttpURLConnection) url.openConnection();
  7.             urlConnection.setReadTimeout(10000);
  8.             urlConnection.setConnectTimeout(15000);
  9.             urlConnection.setRequestMethod("GET");
  10.             urlConnection.connect();
  11.             inputStream = new BufferedInputStream(urlConnection.getInputStream());
  12.         } catch (MalformedURLException e) {
  13.             e.printStackTrace();
  14.         } catch (IOException e) {
  15.             e.printStackTrace();
  16.         } catch (Exception e) {
  17.             e.getMessage();
  18.         } finally {
  19.             assert urlConnection != null;
  20.             urlConnection.disconnect();
  21.         }
  22.         return inputStream;
  23.     }
複製代碼

作者: 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