출처 : http://whitegom.tistory.com/26
import java.io.BufferedReader; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.URL; public class httpGetXmlTest { public static void main(String[] args) throws Exception { // TODO Auto-generated method stub URL url = new URL("http://192.168.137.130:8080/exam/xml3/admin"); // open connection HttpURLConnection conn = (HttpURLConnection) url.openConnection(); conn.setDoInput(true); // 입력스트림 사용 conn.setDoOutput(true); // 출력스트림 사용 conn.setUseCaches(false); // 캐시사용 안함 conn.setReadTimeout(30000); // 타임아웃 : 3초 conn.setRequestMethod("GET"); // GET or POST ... StringBuffer sb = new StringBuffer(); BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream())); for (;;) { String line = br.readLine(); if (line == null) break; sb.append(line + "\n"); } br.close(); conn.disconnect(); String getXml = sb.toString(); System.out.println(sb.toString()); } }
댓글 없음 :
댓글 쓰기