get请求
String body = HttpUtil.createGet("www.baidu.com").execute().body();
post请求
// 构建表单POST请求
HttpRequest request = HttpRequest.post(url)
.header("Content-Type", "application/x-www-form-urlencoded") // 表单类型的Content-Type
.form("key1", "value1")
.form("key2", "value2");
// 构建body POST请求
// 请求的URL
String url = "http://example.com/api/post";
// 构建POST请求
HttpRequest request = HttpRequest.post(url)
.header("Content-Type", "application/json") // 设置请求头
.body("{\"key\":\"value\"}"); // 设置请求体,这里是一个JSON字符串
// 发送请求,并接收响应
HttpResponse response = request.execute();
// 打印响应的内容
System.out.println(response.body());
还可以用jsonObject 转换成String
JSONObject jsonObject = new JSONObject();
jsonObject.put("profile_id",userProFileMap.get(authDTO.getUserId()));
jsonObject.put("timezone",authDTO.getTimezone());
jsonObject.put("officeCode",authDTO.getOfficeCode());
String result = HttpUtil.post(updateUpfUserTimezoneUrl, JSON.toJSONString(jsonObject));
标签:body,HttpRequest,请求,jsonObject,hutool,发送,post,String
From: https://blog.csdn.net/weixin_44001799/article/details/137595296