프로젝트 과업 진행중 진행한 방법을 안 까먹으려고 작성
우선 처음엔 국내 ip 대역폭을 db에 화이트리스트처럼 저장해두고 체크할까하다가
한국인터넷진흥원에 오픈API를 제공하는게 있어서 그거 사용
API 예시는 인터넷 진흥원에 있으니 넘어가고
받아와서 그 후 xml로 응답받은 데이터를 처리하여 원하는 데이터만 뽑는 부분만 적어두려함
DocumentBuilderFactory fac = DocumentBuilderFactory.newInstance();
try{
DocumentBuilder builder = fac.newDocumentBuilder();
try{
// sb는 StringBuilder에 응답받은 xml 데이터를 담고 있는 변수
Document doc = builder.parse(new InputSource(new StringReader(sb.toString())));
// 저의 경우 국가코드를 받아 그걸 구분값으로 쓰려해서 countryCode로 작성함
NodeList node = doc.getElementsByTagName("countryCode");
Node text = node.item(0).getChildNodes().item(0);
System.out.println(text.getNodeValue());
} catch (SAXException e) {
e.getMessage();
}
} catch (ParserConfigurationException e) {
e.getMessage();
}
'언어 > JAVA' 카테고리의 다른 글
poi 엑셀 셀 병합 (0) | 2022.08.31 |
---|---|
HSSFCellStyle 셀 스타일 배경색 지정 (0) | 2022.07.25 |
시큐어코딩 TOCTOU 해결 방법 (0) | 2022.02.26 |
보안 - 불충분 한 랜덤 값 사용 (0) | 2022.02.23 |
Optional 클래스 (0) | 2021.05.05 |