본문으로 바로가기

URL 호출

category Backend/Java 2020. 7. 7. 13:49
BufferedReader in = null;
			
try {
	URL obj = new URL("주소"); // 호출할 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(); }
}

'Backend > Java' 카테고리의 다른 글

properties && @Value 사용하기  (0) 2020.09.04
BufferedReader  (0) 2020.07.28
IP 및 모바일 체크  (0) 2020.03.23
Java 파일 압축 및 특정 파일 리스트 추출  (0) 2020.02.21
Struts2 textfield Null 인 경우  (0) 2020.02.17