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");
}
}
}