본문 바로가기

개발 관련 지식/자바(Java)

[자바] URL 호출 방법

* URL 호출 방법

 

[URL 호출 예제]

 

public class HttpSendSource {
		public String urlCall(String requesturl) {
			URL url = null;
			String requestMsg = "";
			String line = "";
			BufferedReader input = null;
			try {// Request
				url = new URL(requesturl);
				// Response
				input = new BufferedReader(new InputStreamReader(url.openStream()));
				
					while((line=input.readLine()) != null){ requestMsg += line; }
					
				System.out.println("requestMsg[" + requestMsg + "]");
			} catch (Exception e) {
				e.printStackTrace();
			}
			return requestMsg;
		}
	}