public void sendPostRequestByForm(String path, String params) throws Exception{
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(path);
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
StringEntity entity = new StringEntity(params,"UTF-8");
post.setEntity(entity);
CloseableHttpResponse response = client.execute(post);
CloseableHttpClient client = HttpClients.createDefault();
HttpPost post = new HttpPost(path);
post.setHeader(HttpHeaders.CONTENT_TYPE, "application/json;charset=UTF-8");
StringEntity entity = new StringEntity(params,"UTF-8");
post.setEntity(entity);
CloseableHttpResponse response = client.execute(post);
}
public void test(){
//将实体转换成json格式
ObjectMapper mapper = new ObjectMapper();
sendPostRequestByForm(path,mapper.writeValueAsString(legacyUserDTO));
}