Feign调用远程服务时传递Cookie信息

@Configuration
public class TtpfFeignConfig {
    @Bean
    public RequestInterceptor requestInterceptor(){//Feign同步请求头
        return template -> {
            ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
            if (requestAttributes != null) {
                HttpServletRequest request = requestAttributes.getRequest();
                template.header("Cookie",request.getHeader("Cookie"));
            }
        };
    }
}

 

posted @ 2024-03-07 19:45  Yfeil  阅读(425)  评论(0编辑  收藏  举报