馬上加入Android 台灣中文網,立即免費下載應用遊戲。
您需要 登錄 才可以下載或查看,沒有帳號?註冊
x
我要抓取政府的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;
- }
複製代碼 |

|