/* 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/convergence2017/conver2"); /*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("keyword","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/convergence2017/conver2'; /*URL*/
var queryParams = '?' + encodeURIComponent('serviceKey') + '=' + '서비스키'; /*서비스키*/
queryParams += '&' + encodeURIComponent('numOfRows') + '=' + encodeURIComponent('세션당 요청레코드수'); /*세션당 요청레코드수*/
queryParams += '&' + encodeURIComponent('pageNo') + '=' + encodeURIComponent('페이지수'); /*페이지수*/
queryParams += '&' + encodeURIComponent('keyword') + '=' + 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("rnum" + $(this).find("rnum").text());
console.log("title" + $(this).find("title").text());
console.log("description" + $(this).find("description").text());
console.log("abstractDesc" + $(this).find("abstractDesc").text());
console.log("affiliation" + $(this).find("affiliation").text());
console.log("alternativeTitle" + $(this).find("alternativeTitle").text());
console.log("charge" + $(this).find("charge").text());
console.log("collectionDb" + $(this).find("collectionDb").text());
console.log("contributor" + $(this).find("contributor").text());
console.log("copyrightOthers" + $(this).find("copyrightOthers").text());
console.log("coverage" + $(this).find("coverage").text());
console.log("createdDate" + $(this).find("createdDate").text());
console.log("creator" + $(this).find("creator").text());
console.log("digitalizedDate" + $(this).find("digitalizedDate").text());
console.log("extent" + $(this).find("extent").text());
console.log("format" + $(this).find("format").text());
console.log("grade" + $(this).find("grade").text());
console.log("venue" + $(this).find("venue").text());
console.log("spatial" + $(this).find("spatial").text());
console.log("temporal" + $(this).find("temporal").text());
console.log("time" + $(this).find("time").text());
console.log("type" + $(this).find("type").text());
console.log("identifier" + $(this).find("identifier").text());
console.log("issuedDate" + $(this).find("issuedDate").text());
console.log("medium" + $(this).find("medium").text());
console.log("period" + $(this).find("period").text());
console.log("person" + $(this).find("person").text());
console.log("publisher" + $(this).find("publisher").text());
console.log("reference" + $(this).find("reference").text());
console.log("regDate" + $(this).find("regDate").text());
console.log("relation" + $(this).find("relation").text());
console.log("rights" + $(this).find("rights").text());
console.log("source" + $(this).find("source").text());
console.log("subjectCategory" + $(this).find("subjectCategory").text());
console.log("subjectKeyword" + $(this).find("subjectKeyword").text());
console.log("subDescription" + $(this).find("subDescription").text());
console.log("tableOfContents" + $(this).find("tableOfContents").text());
console.log("uci" + $(this).find("uci").text());
console.log("url" + $(this).find("url").text());
console.log("localarea" + $(this).find("localarea").text());
console.log("tm10m" + $(this).find("tm10m").text());
console.log("hm10m" + $(this).find("hm10m").text());
console.log("wd10m" + $(this).find("wd10m").text());
console.log("ws10m" + $(this).find("ws10m").text());
console.log("rn" + $(this).find("rn").text());
console.log("cpRn" + $(this).find("cpRn").text());
console.log("pa" + $(this).find("pa").text());
console.log("ts" + $(this).find("ts").text());
console.log("tm2m" + $(this).find("tm2m").text());
console.log("hm2m" + $(this).find("hm2m").text());
console.log("wd2m" + $(this).find("wd2m").text());
console.log("ws2m" + $(this).find("ws2m").text());
console.log("insertDate" + $(this).find("insertDate").text());
console.log("wd10mstr" + $(this).find("wd10mstr").text());
console.log("wd2mstr" + $(this).find("wd2mstr").text());
});
};
}
xhr.send('');