/* Java Sample */
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.io.BufferedReader;
import java.io.IOException;
public class openApi {
public static void main(String[] args) throws IOException {
StringBuilder urlBuilder = new StringBuilder("http://api.kcisa.kr/openapi/service/rest/convergence2018/conver7"); /*URL*/
urlBuilder.append("?" + URLEncoder.encode("serviceKey","UTF-8") + "=서비스키"); /*서비스키*/
urlBuilder.append("&" + URLEncoder.encode("numOfRows","UTF-8") + "=" + URLEncoder.encode("세션당 요청레코드수", "UTF-8")); /*세션당 요청레코드수*/
urlBuilder.append("&" + URLEncoder.encode("pageNo","UTF-8") + "=" + URLEncoder.encode("페이지수", "UTF-8")); /*페이지수*/
urlBuilder.append("&" + URLEncoder.encode("sido","UTF-8") + "=" + URLEncoder.encode("시도", "UTF-8")); /*시도*/
urlBuilder.append("&" + URLEncoder.encode("gungu","UTF-8") + "=" + URLEncoder.encode("군구", "UTF-8")); /*군구*/
URL url = new URL(urlBuilder.toString());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Content-type", "application/json");
//json type으로 응답받고 싶을 때는 아래 주석을 제거하시고 사용바랍니다.
//conn.setRequestProperty("Accept","application/json");
System.out.println("Response code: " + conn.getResponseCode());
BufferedReader rd;
if(conn.getResponseCode() >= 200 && conn.getResponseCode() <= 300) {
rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
} else {
rd = new BufferedReader(new InputStreamReader(conn.getErrorStream()));
}
StringBuilder sb = new StringBuilder();
String line;
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
conn.disconnect();
System.out.println(sb.toString());
}
}
/* Javascript Sample*/
var xhr = new XMLHttpRequest();
var url = 'http://api.kcisa.kr/openapi/service/rest/convergence2018/conver7'; /*URL*/
var queryParams = '?' + encodeURIComponent('serviceKey') + '=' + '서비스키'; /*서비스키*/
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('세션당 요청레코드수'); /*세션당 요청레코드수*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('페이지수'); /*페이지수*/
queryParams += '&' + encodeURIComponent('sido') + '=' + encodeURIComponent('시도'); /*시도*/
queryParams += '&' + encodeURIComponent('gungu') + '=' + encodeURIComponent('군구'); /*군구*/
xhr.open('GET', url + queryParams);
xhr.onreadystatechange = function () {
if (this.readyState == 4) {
console.log('status: ' + this.status);
console.log('resultCode: ' + $(this.responseText).find('resultCode').text());
console.log('resultMsg: ' + $(this.responseText).find('resultMsg').text());
var item = $(this.responseText).find('item');
$(item).each(function(){
console.log("address" + $(this).find("address").text());
console.log("address2" + $(this).find("address2").text());
console.log("category1" + $(this).find("category1").text());
console.log("category2" + $(this).find("category2").text());
console.log("creator" + $(this).find("creator").text());
console.log("gungu" + $(this).find("gungu").text());
console.log("insertDate" + $(this).find("insertDate").text());
console.log("lat" + $(this).find("lat").text());
console.log("lon" + $(this).find("lon").text());
console.log("parkingyn" + $(this).find("parkingyn").text());
console.log("publisher" + $(this).find("publisher").text());
console.log("regDate" + $(this).find("regDate").text());
console.log("rnum" + $(this).find("rnum").text());
console.log("roomName" + $(this).find("roomName").text());
console.log("sido" + $(this).find("sido").text());
console.log("subject" + $(this).find("subject").text());
console.log("totalCapacity" + $(this).find("totalCapacity").text());
console.log("servName" + $(this).find("servName").text());
console.log("ssid" + $(this).find("ssid").text());
console.log("wInsDate" + $(this).find("wInsDate").text());
console.log("toiletyn" + $(this).find("toiletyn").text());
console.log("cnt1" + $(this).find("cnt1").text());
console.log("cnt2" + $(this).find("cnt2").text());
console.log("time" + $(this).find("time").text());
console.log("contact" + $(this).find("contact").text());
console.log("category3" + $(this).find("category3").text());
console.log("category4" + $(this).find("category4").text());
console.log("homepage" + $(this).find("homepage").text());
console.log("category5" + $(this).find("category5").text());
console.log("sigungu" + $(this).find("sigungu").text());
console.log("affiliation" + $(this).find("affiliation").text());
console.log("tInsDate" + $(this).find("tInsDate").text());
console.log("description" + $(this).find("description").text());
});
};
}
xhr.send('');