Feign请求头的值为JSON格式时传递有截断问题

This commit is contained in:
macro
2022-07-24 10:24:17 +08:00
parent e0bd4259e8
commit 2cc7a54b9a

View File

@@ -1,5 +1,8 @@
package com.macro.mall.demo.component;
import cn.hutool.core.util.StrUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import org.springframework.web.context.request.RequestContextHolder;
@@ -24,6 +27,12 @@ public class FeignRequestInterceptor implements RequestInterceptor {
while (headerNames.hasMoreElements()) {
String name = headerNames.nextElement();
String values = request.getHeader(name);
//请求头的值为JSON格式时有截断问题
if("user".equals(name)&&StrUtil.isNotEmpty(values)){
JSONObject jsonObject = JSONUtil.parseObj(values);
String id = jsonObject.getStr("id");
values = JSONUtil.createObj().putOnce("id",id).toString();
}
requestTemplate.header(name, values);
}
}