|
@@ -10,6 +10,7 @@ import org.apache.http.conn.socket.ConnectionSocketFactory;
|
|
|
import org.apache.http.conn.socket.PlainConnectionSocketFactory;
|
|
|
import org.apache.http.conn.ssl.NoopHostnameVerifier;
|
|
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
import org.apache.http.impl.client.HttpClients;
|
|
|
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
|
|
@@ -159,15 +160,9 @@ public class HttpUtil {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 发送 post 请求
|
|
|
+ * 自定义请求头的 post 请求
|
|
|
*/
|
|
|
- public static String post(
|
|
|
- CloseableHttpClient closeableHttpClient,
|
|
|
- RequestConfig requestConfig,
|
|
|
- String url,
|
|
|
- Map<String, String> headers,
|
|
|
- Map<String, String> params
|
|
|
- ) throws Exception {
|
|
|
+ public static String post(CloseableHttpClient closeableHttpClient, RequestConfig requestConfig, String url, Map<String, String> headers, Map<String, String> params) throws IOException {
|
|
|
//1 创建 post 请求
|
|
|
HttpPost post = new HttpPost(url);
|
|
|
//2 设置请求默认配置
|
|
@@ -177,8 +172,9 @@ public class HttpUtil {
|
|
|
headers.forEach(post::setHeader);
|
|
|
}
|
|
|
//4 设置请求体
|
|
|
+ post.addHeader("Content-Type", "application/json");
|
|
|
if (!CollectionUtil.isEmpty(params)) {
|
|
|
- params.forEach(post::setHeader);
|
|
|
+ post.setEntity(new StringEntity(JsonUtil.beanToJson(params), "utf-8"));
|
|
|
}
|
|
|
//5 发送请求
|
|
|
CloseableHttpResponse response = closeableHttpClient.execute(post);
|
|
@@ -192,7 +188,6 @@ public class HttpUtil {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
//
|
|
|
// /**
|
|
|
// * 通过 get 请求下载文件
|