프로젝트/버스카드조회
HttpURLConnection 클래스
IT grow.
2018. 9. 16. 18:39
반응형
import java.io.BufferedReader;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;public class Example {public static void main(String [] args){BufferedReader in = null;try{URL obj = new URL("http://ws.bus.go.kr/api/rest/buspos/getBusPosByRtid?busRouteId=1111111");# 여기서 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){System.out.println(line);}}catch(Exception e){e.printStackTrace();}finally{if(in != null){try{in.close();}catch(Exception e){e.printStackTrace();}}}}}
반응형