接口说明:

POSTMAN测试:

JAVA代码:
1package com.provy.guard.api; 2 3import java.util.HashMap; 4import java.util.Map; 5 6import cn.hutool.http.HttpUtil; 7import cn.hutool.json.JSONObject; 8import cn.hutool.json.JSONUtil; 9 10/** 11 * Hutool工具里,POST方法,body中传参的几种调用方法 12 * @author wangxy 13 * 14 */ 15public class Test { 16 17 public static void main(String[] args) { 18 post1();// 成功 19 post2();// 成功 20 post3();// 失败 21 post4();// 成功 22 } 23 24 public static void post1() { 25 String param = "{\"StartTime\":\"2018-10-10 09:42:02\",\"EndTime\":\"2018-10-29 09:42:02\",\"StartIndex\":\"0\",\"PageSize\":\"30\"}"; 26 String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param); 27 System.out.println(result); 28 } 29 30 public static void post2() { 31 JSONObject param = JSONUtil.createObj(); 32 param.put("StartTime", "2018-10-10 09:42:02"); 33 param.put("EndTime", "2018-10-29 09:42:02"); 34 param.put("StartIndex", 0); 35 param.put("PageSize", 30); 36 String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param.toString()); 37 System.out.println(result); 38 } 39 40 public static void post3() { 41 Map<String, Object> param = new HashMap<String, Object>(); 42 param.put("StartTime", "2018-10-10 09:42:02"); 43 param.put("EndTime", "2018-10-29 09:42:02"); 44 param.put("StartIndex", "0"); 45 param.put("PageSize", "30"); 46 String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param); 47 System.out.println(result); 48 } 49 50 public static void post4() { 51 JSONObject json = JSONUtil.createObj(); 52 String result = HttpUtil.createPost("http://localhost:8080/v1/hitrecord/2").body(json).execute().body(); 53 System.out.println(result); 54 } 55 56}