/* 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/API_CNV_065/request"); /*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("schNm","UTF-8") + "=" + URLEncoder.encode("학교명(필수값, 2자이상)", "UTF-8")); /*학교명(필수값, 2자이상)*/
urlBuilder.append("&" + URLEncoder.encode("dist","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/API_CNV_065/request'; /*URL*/
var queryParams = '?' + encodeURIComponent('serviceKey') + '=' + '서비스키'; /*서비스키*/
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('세션당 요청레코드수'); /*세션당 요청레코드수*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('페이지수'); /*페이지수*/
queryParams += '&' + encodeURIComponent('schNm') + '=' + encodeURIComponent('학교명(필수값, 2자이상)'); /*학교명(필수값, 2자이상)*/
queryParams += '&' + encodeURIComponent('dist') + '=' + 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("schNm" + $(this).find("schNm").text());
console.log("schTp" + $(this).find("schTp").text());
console.log("instDt" + $(this).find("instDt").text());
console.log("schRoadAddr" + $(this).find("schRoadAddr").text());
console.log("schLatPos" + $(this).find("schLatPos").text());
console.log("schLotPos" + $(this).find("schLotPos").text());
console.log("fcltyNm" + $(this).find("fcltyNm").text());
console.log("lclasNm" + $(this).find("lclasNm").text());
console.log("fcltyRoadNmAddr" + $(this).find("fcltyRoadNmAddr").text());
console.log("description" + $(this).find("description").text());
console.log("subDescription" + $(this).find("subDescription").text());
console.log("homepageUrl" + $(this).find("homepageUrl").text());
console.log("telNo" + $(this).find("telNo").text());
console.log("openInstNm" + $(this).find("openInstNm").text());
console.log("pvsnInstNm" + $(this).find("pvsnInstNm").text());
console.log("dataStdDate" + $(this).find("dataStdDate").text());
console.log("fcltyLatPos" + $(this).find("fcltyLatPos").text());
console.log("fcltyLotPos" + $(this).find("fcltyLotPos").text());
console.log("dist" + $(this).find("dist").text());
});
};
}
xhr.send('');