1
0
mirror of synced 2025-12-13 18:34:29 +08:00

🎨 修复CloseableHttpClient相关的误用代码

This commit is contained in:
altusea
2025-05-22 15:03:27 +08:00
committed by GitHub
parent 3e1a38a696
commit 8bacc9425e
41 changed files with 240 additions and 443 deletions

View File

@@ -3,14 +3,13 @@ package me.chanjar.weixin.qidian.api.impl;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.error.WxRuntimeException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.apache.ApacheBasicResponseHandler;
import me.chanjar.weixin.common.util.http.apache.ApacheHttpClientBuilder;
import me.chanjar.weixin.common.util.http.apache.DefaultApacheHttpClientBuilder;
import me.chanjar.weixin.qidian.config.WxQidianConfigStorage;
import org.apache.http.HttpHost;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.CloseableHttpClient;
import java.io.IOException;
@@ -86,11 +85,8 @@ public class WxQidianServiceHttpClientImpl extends BaseWxQidianServiceImpl<Close
RequestConfig requestConfig = RequestConfig.custom().setProxy(this.getRequestHttpProxy()).build();
httpGet.setConfig(requestConfig);
}
try (CloseableHttpResponse response = getRequestHttpClient().execute(httpGet)) {
return this.extractAccessToken(new BasicResponseHandler().handleResponse(response));
} finally {
httpGet.releaseConnection();
}
String responseContent = getRequestHttpClient().execute(httpGet, ApacheBasicResponseHandler.INSTANCE);
return this.extractAccessToken(responseContent);
} catch (IOException e) {
throw new WxRuntimeException(e);
}