Java/utils
apache http utils 예제
무대포 개발자
2020. 11. 8. 11:58
728x90
반응형
apache http utils 예제
- json 문자를 http post 방식으로 보내는 예제
라이브러리
source
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost("http://localhost:8080/test");
String json = "{"test:test"}";
HttpEntity stringEntity = new StringEntity(json, ContentType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
CloseableHttpResponse response = client.execute(httpPost);
/** response 관련 후속 조치 로직을 넣어주면 됨. */
HttpEntity entity = response.getEntity();
EntityUtils.consume(entity);