话题不多说,直接开整
1、先导入依赖
<dependency>
<groupId>io.github.admin4j</groupId>
<artifactId>common-http-starter</artifactId>
<version>0.4.2</version>
</dependency>
2、测试类开始测试
@Test
public void testGet() {
Response response = HttpUtil.get("https://github.com/search", Pair.of("q", "okhttp"));
System.out.println("response = " + response);
}
@Test
public void testPost() {
Response post = HttpUtil.post("https://oapi.dingtalk.com/robot/send?access_token=27f5954ab60ea8b2e431ae9101b1289c138e85aa6eb6e3940c35ee13ff8b6335", "{\"msgtype\": \"text\",\"text\": {\"content\":\"【反馈提醒】我就是我, 是不一样的烟火\"}}");
System.out.println("post = " + post);
Map<String, Object> formParams = new HashMap<>(16);
formParams.put("username", "qbb");
formParams.put("password", "Qiu123456.");
Response response = HttpUtil.postForm("http://127.0.0.1:8080/user/login",
formParams
);
System.out.println("response = " + response);
}
@Test
public void testJson() {
JSONObject object = HttpJsonUtil.get("http://127.0.0.1:8080/user/list/1/5",
Pair.of("q", "http"),
Pair.of("username", "qbbit"));
System.out.println("object = " + object);
}
@Test
public void testDown() throws IOException {
HttpUtil.down("https://gitee.com/admin4j/common-http", "serverFile/");
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构