使用情景:在一个项目中需要通过接口调用另一个项目的某一个方法时使用。
代码如下:
发送post请求工具类:
package com.cosmoseye.core.utils;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.Future;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.apache.http.util.EntityUtils;
import org.springframework.scheduling.annotation.AsyncResult;
import com.alibaba.fastjson.JSONObject;
import com.cosmoseye.core.entity.ArticleAnalysisDto;
public class SendPost {
public static Future<String> doPostJson(List<ArticleAnalysisDto> articleList, String dir ) {
// 创建Httpclient对象
CloseableHttpClient httpClient = HttpClients.createDefault();
CloseableHttpResponse response &#