Forest-HTTP客户端框架学习笔记
<!--引入依赖-->
<dependency>
<groupId>com.dtflys.forest</groupId>
<artifactId>forest-spring-boot-starter</artifactId>
<version>1.5.36</version>
</dependency>
applicant.yam加入以下配置
forest:
max-connections: 1000 # 连接池最大连接数
connect-timeout: 3000 # 连接超时时间,单位为毫秒
read-timeout: 3000 # 数据读取超时时间,单位为毫秒
在启动类Application指定路径
@ForestScan(basePackages = "com.example.thymeleaf.client")
创建Client接口
package com.example.thymeleaf.client;
import com.dtflys.forest.annotation.Body;
import com.dtflys.forest.annotation.Post;
public interface MyClient {
/**
* 配置拦截器测试
*
* @param username
* @return
*/
@Post(
url = "http://some/path",
contentType = "application/x-www-form-urlencoded"
)
String testInterceptor(@Body("APPID") String value1, @Body("imaMag") String value2);
}
Controller层
//引入MyClient
@Resource
MyClient myClient;
@RequestMapping("/testClient")
public String testClient() {
String location = myClient.testInterceptor("APP","FGDGHDGAUFEHANFNA");
System.out.println(location);
return location;
}
推荐一篇文章:轻量级HTTP客户端框架—Forest学习笔记_forest框架-CSDN博客