Skip to content

WxPayServiceApacheHttpImpl.java中使用HttpClient发送http请求时可以调整为使用连接池的形式吗? #3640

@Fighthub

Description

@Fighthub

WxPayServiceApacheHttpImpl.java这个类中发送http请求时,可以使用连接池的形式吗?这里没有使用连接池是有哪方面的考虑吗?
@Override public String post(String url, String requestStr, boolean useKey) throws WxPayException { try { HttpClientBuilder httpClientBuilder = this.createHttpClientBuilder(useKey); HttpPost httpPost = this.createHttpPost(url, requestStr); try (CloseableHttpClient httpClient = httpClientBuilder.build()) { try (CloseableHttpResponse response = httpClient.execute(httpPost)) { String responseString = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8); this.logRequestAndResponse(url, requestStr, responseString); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, responseString, null)); } return responseString; } } finally { httpPost.releaseConnection(); } } catch (Exception e) { this.logError(url, requestStr, e); if (this.getConfig().isIfSaveApiData()) { wxApiData.set(new WxPayApiData(url, requestStr, null, e.getMessage())); } throw new WxPayException(e.getMessage(), e); } }

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions