develop/java
JAVA API 호출
hybr1d
2017. 12. 20. 10:17
BufferedReader in = null;
try {
String url = "abc";
String parameter = "a=b";
url = url + URLEncoder.encode(parameter, "UTF-8");
URL obj = new URL("http://www.test.co.kr/test.jsp"); // 호출할 url
HttpURLConnection con = (HttpURLConnection)obj.openConnection();
con.setRequestMethod("GET");
in = new BufferedReader(new InputStreamReader(con.getInputStream(), "UTF-8"));
String line;
while((line = in.readLine()) != null) { // response를 차례대로 출력
System.out.println(line);
}
} catch(Exception e) {
e.printStackTrace();
} finally {
if(in != null)
try {
in.close();
} catch(Exception e) {
e.printStackTrace();
}
}