Hutool工具里,POST方法,body中传参的几种调用方法

接口说明:

Hutool工具里,POST方法,body中传参的几种调用方法

POSTMAN测试:

Hutool工具里,POST方法,body中传参的几种调用方法

JAVA代码:

package com.provy.guard.api;

import java.util.HashMap;
import java.util.Map; import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil; /**
* Hutool工具里,POST方法,body中传参的几种调用方法
* @author wangxy
*
*/
public class Test { public static void main(String[] args) {
post1();// 成功
post2();// 成功
post3();// 失败
post4();// 成功
} public static void post1() {
String param = "{\"StartTime\":\"2018-10-10 09:42:02\",\"EndTime\":\"2018-10-29 09:42:02\",\"StartIndex\":\"0\",\"PageSize\":\"30\"}";
String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param);
System.out.println(result);
} public static void post2() {
JSONObject param = JSONUtil.createObj();
param.put("StartTime", "2018-10-10 09:42:02");
param.put("EndTime", "2018-10-29 09:42:02");
param.put("StartIndex", 0);
param.put("PageSize", 30);
String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param.toString());
System.out.println(result);
} public static void post3() {
Map<String, Object> param = new HashMap<String, Object>();
param.put("StartTime", "2018-10-10 09:42:02");
param.put("EndTime", "2018-10-29 09:42:02");
param.put("StartIndex", "0");
param.put("PageSize", "30");
String result = HttpUtil.post("http://localhost:8080/v1/hitrecord/2", param);
System.out.println(result);
} public static void post4() {
JSONObject json = JSONUtil.createObj();
String result = HttpUtil.createPost("http://localhost:8080/v1/hitrecord/2").body(json).execute().body();
System.out.println(result);
} }
上一篇:MemSQL start[c]up Round 1.E


下一篇:js URL中文传参乱码