1
HttpResponse 객체를 호출 함수에 반환하는 httpClient 함수가 있습니다. 내 호출하는 함수에서HttpResponse 객체를 사용할 때 소켓을 닫는 중 오류가 발생했습니다.
public HttpResponse postRequest(String uri, String body) throws IOException {
HttpResponse response;
String url = baseUrl + uri;
try (CloseableHttpClient httpClient = HttpClientBuilder.create()
.build()) {
HttpPost post = new HttpPost(url);
post.setEntity(new StringEntity(body));
post.setHeader(AUTHORIZATION_HEADER, authorization);
post.setHeader(CONTENTTYPE_HEADER, APPLICATION_JSON);
post.setHeader(ACCEPT_HEADER, APPLICATION_JSON);
response = httpClient.execute(post);
} catch (IOException e) {
System.out.println("Caught an exception" + e.getMessage().toString());
logger.error("Caught an exception" + e.getMessage().toString());
throw e;
}
return response;
}
내가 전화, HttpResponse response = httpRequest.postRequest(url,body);
는 (여기서 HttpRequest를 함수
내가
String responseString = IOUtils.toString(response.getEntity()
.getContent(), "UTF-8");
를 통해 수신 된 응답의 내용을 구문 분석하려고 들어있는 클래스의 객체이다
소켓이 닫혔습니다.
일단 연결이 닫히면 HttpResponse의 내용을 어떻게 사용합니까?
예를 들어 주시겠습니까? 나는 너를 따라 가지 않았다. – user1692342