HttpClient

来源:互联网 发布:公文流转软件 编辑:程序博客网 时间:2024/06/09 23:25
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);

    }

public void test(){

//将实体转换成json格式

ObjectMapper mapper = new ObjectMapper();

sendPostRequestByForm(path,mapper.writeValueAsString(legacyUserDTO));

}


原创粉丝点击