HTTP通信でXML取得
HttpURLConnection conn = null;
try {
// HTTP通信開始
URL url = new URL("http://localhost/hoge");
conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
conn.connect();
// パラメータ送信
PrintStream ps = new PrintStream(conn.getOutputStream());
ps.print("a=111&b=222");
ps.flush();
ps.close();
// レスポンス受信
InputStream is = conn.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder xml = new StringBuilder();
String s;
while ((s = reader.readLine()) != null) {
xml.append(s);
}
is.close();
return xml.toString();
} catch(Exception e) {
e.printStackTrace();
} finally {
conn.disconnect();
}