반응형
HttpURLConnection을 이용하여 Java 상에서 타 시스템의 JSON 결과 값을 받아 올 수 있다.
String json = "";
URL postUrl = new URL('URL 경로');
HttpURLConnection connection = (HttpURLConnection) postUrl.openConnection();
connection.setDoOutput(true); // xml내용을 전달하기 위해서 출력 스트림을 사용
connection.setInstanceFollowRedirects(false); //Redirect처리 하지 않음
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type", "application/json");
BufferedReader br = new BufferedReader(new InputStreamReader((connection.getInputStream())));
String output;
while ((output = br.readLine()) != null) {
json += output;
}
connection.disconnect();
//String to JsonNode
ObjectMapper objectMapper = new ObjectMapper();
JsonNode root = objectMapper.readTree(json);
반응형
'프로그래밍 > Java' 카테고리의 다른 글
Java 버전별 역사 및 특징 (0) | 2017.10.11 |
---|---|
Properties 읽고 쓰기 (0) | 2014.09.26 |
JDK 설치 방법 (0) | 2013.10.07 |
JAVA JDK 다운로드 (0) | 2013.10.07 |
댓글