mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-20 10:38:13 +08:00
issue #29 http代理支持
This commit is contained in:
@@ -11,13 +11,23 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* http请求执行器
|
* http请求执行器
|
||||||
* @author Daniel Qian
|
|
||||||
*
|
*
|
||||||
* @param <T> 返回值类型
|
* @param <T> 返回值类型
|
||||||
* @param <E> 请求参数类型
|
* @param <E> 请求参数类型
|
||||||
*/
|
*/
|
||||||
public interface RequestExecutor<T, E> {
|
public interface RequestExecutor<T, E> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @param httpclient 传入的httpClient
|
||||||
|
* @param httpProxy http代理对象,如果没有配置代理则为空
|
||||||
|
* @param uri uri
|
||||||
|
* @param data 数据
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
* @throws ClientProtocolException
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
public T execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, E data) throws WxErrorException, ClientProtocolException, IOException;
|
public T execute(CloseableHttpClient httpclient, HttpHost httpProxy, String uri, E data) throws WxErrorException, ClientProtocolException, IOException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -25,6 +25,7 @@ import org.apache.http.auth.AuthScope;
|
|||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.CredentialsProvider;
|
import org.apache.http.client.CredentialsProvider;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.impl.client.BasicCredentialsProvider;
|
import org.apache.http.impl.client.BasicCredentialsProvider;
|
||||||
@@ -85,6 +86,10 @@ public class WxCpServiceImpl implements WxCpService {
|
|||||||
+ "&corpsecret=" + wxCpConfigStorage.getCorpSecret();
|
+ "&corpsecret=" + wxCpConfigStorage.getCorpSecret();
|
||||||
try {
|
try {
|
||||||
HttpGet httpGet = new HttpGet(url);
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
if (httpProxy != null) {
|
||||||
|
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||||
|
httpGet.setConfig(config);
|
||||||
|
}
|
||||||
CloseableHttpClient httpclient = getHttpclient();
|
CloseableHttpClient httpclient = getHttpclient();
|
||||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||||
|
@@ -24,6 +24,7 @@ import org.apache.http.auth.AuthScope;
|
|||||||
import org.apache.http.auth.UsernamePasswordCredentials;
|
import org.apache.http.auth.UsernamePasswordCredentials;
|
||||||
import org.apache.http.client.ClientProtocolException;
|
import org.apache.http.client.ClientProtocolException;
|
||||||
import org.apache.http.client.CredentialsProvider;
|
import org.apache.http.client.CredentialsProvider;
|
||||||
|
import org.apache.http.client.config.RequestConfig;
|
||||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||||
import org.apache.http.client.methods.HttpGet;
|
import org.apache.http.client.methods.HttpGet;
|
||||||
import org.apache.http.client.methods.HttpPost;
|
import org.apache.http.client.methods.HttpPost;
|
||||||
@@ -75,6 +76,10 @@ public class WxMpServiceImpl implements WxMpService {
|
|||||||
;
|
;
|
||||||
try {
|
try {
|
||||||
HttpGet httpGet = new HttpGet(url);
|
HttpGet httpGet = new HttpGet(url);
|
||||||
|
if (httpProxy != null) {
|
||||||
|
RequestConfig config = RequestConfig.custom().setProxy(httpProxy).build();
|
||||||
|
httpGet.setConfig(config);
|
||||||
|
}
|
||||||
CloseableHttpClient httpclient = getHttpclient();
|
CloseableHttpClient httpclient = getHttpclient();
|
||||||
CloseableHttpResponse response = httpclient.execute(httpGet);
|
CloseableHttpResponse response = httpclient.execute(httpGet);
|
||||||
String resultContent = new BasicResponseHandler().handleResponse(response);
|
String resultContent = new BasicResponseHandler().handleResponse(response);
|
||||||
|
Reference in New Issue
Block a user