pom依赖
<!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all -->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.2</version>
</dependency>
GET请求
@Test
public void huToolGet(){
System.out.println("--------------------------------get请求-----------------------------------");
HashMap<String, Object> getParamMaps = new HashMap<>(5);
getParamMaps.put("sortStr", "recordFlag,baseInfo.createTime");
getParamMaps.put("sortDirection", "ASC");
getParamMaps.put("filterStr", "flowAbleInfo.nodeId==craCheck");
getParamMaps.put("pageSize", 10);
getParamMaps.put("pageNo", 0);
HttpResponse getResponse = HttpRequest.get("http://127.0.0.1:8080/szxblog/getlist")
.header("Content-Type", "application/json")
.header("token", "asdsads2522707644436602632758")
.header("kong-request-id", "asdsads2522707644436602632758").form(getParamMaps).execute();
System.out.println("请求响应状态码:" + getResponse.getStatus());
String body1 = getResponse.body();
System.out.println(body1);
JSONObject jsonObject1 = JSONObject.parseObject(body1);
Object msg1 = jsonObject1.get("msg");
}
POST请求
@Test
public void huToolPost() {
System.out.println("--------------------------------post请求-----------------------------------");
HashMap<String, String> paramMaps = new HashMap<>(4);
paramMaps.put("mobile", "123456.");
paramMaps.put("name", "123456.");
HttpResponse response = HttpRequest.post("http://127.0.0.1:8081/szxblog/add")
.header("Content-Type", "application/json")
.header("token", "asdsads2522707644436602632758")
.header("kong-request-id", "asdsads2522707644436602632758")
.body(JSON.toJSONString(paramMaps))
.execute();
System.out.println("请求响应状态码:" + response.getStatus());
String body = response.body();
System.out.println(body);
JSONObject jsonObject = JSONObject.parseObject(body);
Object msg = jsonObject.get("msg");
System.out.println(msg);
Object code = jsonObject.get("code");
System.out.println(code);
}