@RequestMapping(value="/ui/BuilRegInfoUrl1")
public void BuilRegInfoUrl1(HttpServletRequest req, HttpServletResponse res) throws Exception {
String apiurl = "http://apis.data.go.kr/1611000/BldRgstService/getBrTitleInfo?_type=json";
apiurl += "&ServiceKey=YIXasiA1l7fRaRqKnbd1N6B4o4YknUlvdZK2w5ppwQyRdJVYPb4Bgy08uyRQjl4WfILf38A5mgbEiQ%2FpyICLPA%3D%3D";
apiurl += "&sigunguCd=" + req.getParameter("sigunguCd");
apiurl += "&bjdongCd=" + req.getParameter("bjdongCd");
apiurl += "&platGbCd=" + req.getParameter("platGbCd");
apiurl += "&bun=" + req.getParameter("bun");
apiurl += "&ji=" + req.getParameter("ji");
// apiurl += "&startDate=" + req.getParameter("startDate");
// apiurl += "&endDate=" + req.getParameter("endDate");
apiurl += "&numOfRows=" + req.getParameter("numOfRows");
apiurl += "&pageNo=" + req.getParameter("pageNo");
URL url = new URL(apiurl);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(),"UTF-8"));
StringBuffer sb = new StringBuffer();
String tempStr = null;
while(true){
tempStr = br.readLine();
if(tempStr == null) break;
sb.append(tempStr);
}
br.close();
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json");
res.getWriter().write(sb.toString());
}
============================================================================ *공통으로 api 만드는 과정
* Controller
@RequestMapping(value="/ui/BuilRegInfoUrl1")
public void BuilRegInfoUrl1(HttpServletRequest req, HttpServletResponse res) throws Exception {
String BuilRegInfoUrlApiJson = "";
String param = "?_type=json";
String apiUrl = "http://apis.data.go.kr/1611000/BldRgstService/getBrTitleInfo"+ param + ServiceKey;
BuilRegInfoUrlApiJson = gisBimApiServiec.publicDataPortalApi(req, res, apiUrl);
}
* Service
package com.solideos.api.service;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Enumeration;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Service;
/**
* 생성날짜: 2019. 12. 09
*/
@Service
public class GisBimApiServiec {
public String publicDataPortalApi(HttpServletRequest req, HttpServletResponse res, String apiurl) throws Exception {
Enumeration e = req.getParameterNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
// System.out.println(name + " : " + req.getParameter(name));
apiurl += "&" + name + "=" + req.getParameter(name);
}
URL url = new URL(apiurl);
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
StringBuffer sb = new StringBuffer();
String tempStr = null;
while (true) {
tempStr = br.readLine();
if (tempStr == null)
break;
sb.append(tempStr);
}
br.close();
res.setCharacterEncoding("UTF-8");
res.setContentType("application/json");
res.getWriter().write(sb.toString());
return sb.toString();
}
}