|
|
@@ -214,6 +214,10 @@ public class HttpUtil {
|
|
|
return sendRequest(RequestMethod.POST, url, header, params, sign, null);
|
|
|
}
|
|
|
|
|
|
+ public static Response sendPostRequest(String url, HashMap<String, String> header, String body) throws Exception {
|
|
|
+ return sendRequest(RequestMethod.POST, url, header, body, false, null);
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 发送POST请求
|
|
|
*
|
|
|
@@ -479,7 +483,45 @@ public class HttpUtil {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ public static Response sendRequest(RequestMethod method, String url, HashMap<String, String> header, String body, boolean sign, String signKey)
|
|
|
+ throws Exception {
|
|
|
|
|
|
+ HttpPost request = new HttpPost(getRequestUrl(url, sign, signKey));
|
|
|
+ for (Map.Entry<String, String> entry : header.entrySet()) {
|
|
|
+ request.setHeader(entry.getKey(), entry.getValue());
|
|
|
+ }
|
|
|
+ //采用绕过验证的方式处理https请求
|
|
|
+ SSLContext sslcontext = createIgnoreVerifySSL();
|
|
|
+
|
|
|
+ // 设置协议http和https对应的处理socket链接工厂的对象
|
|
|
+ Registry<ConnectionSocketFactory> socketFactoryRegistry = RegistryBuilder.<ConnectionSocketFactory>create()
|
|
|
+ .register("http", PlainConnectionSocketFactory.INSTANCE)
|
|
|
+ .register("https", new SSLConnectionSocketFactory(sslcontext))
|
|
|
+ .build();
|
|
|
+ PoolingHttpClientConnectionManager connManager = new PoolingHttpClientConnectionManager(socketFactoryRegistry);
|
|
|
+ HttpClients.custom().setConnectionManager(connManager);
|
|
|
+
|
|
|
+ //创建自定义的httpclient对象
|
|
|
+ CloseableHttpClient httpClient = HttpClients.custom().setConnectionManager(connManager).build();
|
|
|
+ CloseableHttpResponse response = null;
|
|
|
+ try {
|
|
|
+ request.setEntity(new StringEntity(body));
|
|
|
+ response = httpClient.execute(request);
|
|
|
+ return Response.getResponse(response);
|
|
|
+ } finally {
|
|
|
+ request.releaseConnection();
|
|
|
+ try {
|
|
|
+ httpClient.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ if (response != null) {
|
|
|
+ try {
|
|
|
+ response.close();
|
|
|
+ } catch (IOException e) {
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
/**
|
|
|
* 发起http请求
|
|
|
*
|