【SpringCloud】Feign解决Get请求自动转化成POST的问题

feign接口

@FeignClient(value = CloudClientConfiguation.PORTAL_PROVIDER_CLOUD)
public interface UserProviderService{
    @GetMapping(value = "/user/get-user-info")
    PortalFrontRpcResponse<UserRpcBean> getUserInfo(@RequestBody PortalFrontRpcRequest<UserRpcBean> request);
}

服务提供者

@GetMapping(value = "/user/get-user-info")
public PortalFrontRpcResponse<UserRpcBean> getUserInfo(@RequestBody PortalFrontRpcRequest<UserRpcBean> request){
    //逻辑略
}

调用时报错

抓包显示post请求

原因 

因为Feign默认使用的连接工具实现类,所以里面发现只要你有body体对象,就会强制的把GET请求转换成POST请求。

解决办法

  • 更换Apache的HttpClient。

步骤

  • 加入Feign的配置项
feign:
  httpclient:
    enabled: true
  • 加入这两个依赖
 <dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpclient</artifactId>
   <version>4.5.9</version>
 </dependency>
 <dependency>
    <groupId>io.github.openfeign</groupId>
    <artifactId>feign-httpclient</artifactId>
    <version>10.2.3</version>
 </dependency>

 问题解决!!!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值