注意:模拟此种类型请求时,header会自动生成,不能手动设置,不然会获取不到数据。
//客户端对象
CloseableHttpClient httpClient = HttpClientBuilder.create().setConnectionTimeToLive(2, TimeUnit.SECONDS).build();
//请求对象
HttpPost httpPost = new HttpPost("url");
//body参数
MultipartEntityBuilder entityBuilder = MultipartEntityBuilder.create();
entityBuilder.addTextBody("username","xxx");
entityBuilder.addTextBody("password","xxx");
//设置body参数
httpPost.setEntity(entityBuilder.build())
原文地址:https://blog.csdn.net/z_zhenzhen/article/details/89362845