Feignclient 400解决方法

feign.FeignException$BadRequest: [400] during [POST]
保错日志形如:

Caused by: feign.FeignException$BadRequest: [400] during [POST] to [http://xxxx/api/bpm/processoper/complete?billId=0srEBEjLhJjxDmPZ2iEv&comment=%E6%89%A7%E8%A1%8C%E6%8F%90%E4%BE%9B%E6%8A%96%E9%9F%B3%E5%B9%B3%E5%8F%B0%E6%9C%8D%E5%8A%A1%E8%B4%B9%E6%98%8E%E7%BB%86&assigns=71cb3b2ddcdc4bb7914c7ccfc726d767] [ProcessOperClient#completeTask(String,String,String[])]: [<!doctype html><html lang="en"><head><title>HTTP Status 400 – Bad Request</title><style type="text/css">body {font-family:Tahoma,Arial,sans-serif;} h1, h2, h3, b {color:white;background-color:#525D76;... (1946 bytes)]

调用的api接口如下:

    @PostMapping("/complete")
    public ResponseBase completeTask(@RequestParam("billId") String billId, @RequestParam("comment") String comment,
                                     @RequestParam(name ="assigns",required = false) String[] assigns, @RequestParam(name = "signature", required = false) String signature);

原因:参数拼接在了url中,导致url太长
解决方法:增加FeignInterceptor,将参数放入body中,代码如下

@Configuration
public class FeignInterceptor implements RequestInterceptor {
   
    @Override
    public void apply(RequestTemplate requestTemplate) {
        if ("post".equalsIgnoreCase(requestTemplate.method()) && requestTemplate.body() == null) {
            String query = requestTemplate.queryLine();
            requestTemplate.queries(new HashMap<>());
            if (query!=null && query.startsWith("?")) {
                requestTemplate.body(query.substring(1));
            }
            requestTemplate.header("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
        }
    }

}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值