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