原 hutool实现post和get请求
版权声明:本文为博主原创文章,请尊重他人的劳动成果,转载请附上原文出处链接和本声明。
本文链接:https://www.91mszl.com/zhangwuji/article/details/1432
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.8.12</version>
</dependency>
package com.gaia.plan.controller;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.HashMap;
import java.util.Map;
public class Test {
@PostMapping("/test")
public void test() {
String url="http://localhost:8888/push";
String token="xxx";
Map<String, Object> params=new HashMap<>(16);
params.put("push_message", "");
params.put("push_channel", "");
String json= JSON.toJSONString(params);
String res = HttpRequest.post(url).header("token", token).body(json).execute().body();
}
}
package com.mszl.controller;
import cn.hutool.http.HttpRequest;
import org.springframework.web.bind.annotation.GetMapping;
public class Test {
@GetMapping("/list")
public void list() {
String url="http://localhost:9996/business/list";
String res = HttpRequest.get(url).execute().body();
}
}
2023-04-24 16:02:16 阅读(601)
名师出品,必属精品 https://www.91mszl.com
博主信息