import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;
以下是在接XML中方便接傳值的方法,首先設定要抓取的網頁位置
URL url = new URL("http://localhost/test.jsp");
用HttpURLConnection 開起
HttpURLConnection huc = (HttpURLConnection)url.openConnection();
InputStreamReader之後在寫使用方式
BufferedReader br = new BufferedReader(new InputStreamReader(huc.getInputStream(), "UTF-8"));
一樣用BufferedReader去讀回來
String str = "";
StringBuffer sb = new StringBuffer();
while(null != ((str=br.readLine()))) {
sb.append(str);
}
br.close();
String xmlResponse = sb.toString();
最後要記的關閉連結
br.close();
huc.disconnect();
沒有留言:
張貼留言