2017년 6월 12일 월요일

1. JAVA로 날씨정보, 대기정보 호출...

1. 일단 날씨정보부터...

2. SK 플래닛에서 키발급 받아라!! (알아서 재주껏) 

3. 통신은 Apache HttpClients 4.4로 했음.
public static void getWeather(String lat, String lon){
  httpclient = HttpClients.createDefault();

                String lat = "37.589470";      //조회하고 싶은 위도 경도, 구글 맵에서 값 구하는 것은 상식!
  String lon = "126.673081";

  String callUrl = setLocation(lat, lon, "weather"); //위치 설정 (위도, 경도, return mode) 날씨인지, 대기정보인지...
  
  try {
   HttpGet httpGet = new HttpGet(callUrl);
   httpGet.addHeader("appKey", appKeyId); //발급받은 키를 헤더에 태워서 같이 날려줘야 함..
   //System.out.println(httpGet.getURI());
   //System.out.println("[Executing request]: " + httpGet.getRequestLine());

   HttpResponse response = httpclient.execute(httpGet);

   //System.out.println(response.toString());
   InputStream in;
   in = response.getEntity().getContent();
   printByInputStream(in, "weather");
   in.close();
  } catch (ClientProtocolException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } catch (IOException e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  } finally {
  }
 }

댓글 없음:

댓글 쓰기

[낯선] 2025.02.22 우대락 공연

2025.02.22 우대락 공연 Set List 1. Black Pumas - Colors Covered By 낯선 2. Gate Flowers - 예비역 Covered By 낯선 3. 하동균 - From Mark Covered By 낯선 4. 낯선 ...