为了账号安全,请及时绑定邮箱和手机立即绑定

Springcloud Fegin Get 会自动转成Post

Springcloud Fegin Get 会自动转成Post

心有法竹 2018-10-24 18:33:19
问题描述在实际访问API时,是POST的方式;问题出现的环境背景及自己尝试过哪些方法相关代码// 请把代码文本粘贴到下方(请勿用图片代替代码)@RequestMapping(value = "/permission/current",method = RequestMethod.GET )@Headers({"Content-Type: application/json","Authorization:{token}"}) Map<String,Object> getPermission(@Param("token") String token);你期待的结果是什么?实际看到的错误信息又是什么?怎么修改才可以支持Headers Authorization token,或者是 Springcloud Fegin 在此不支持?
查看完整描述

1 回答

?
慕尼黑5688855

TA贡献1848条经验 获得超2个赞

you can add a Interceptor, put token to header, then you do not have to send token as a param for all the function .

public class FeignBasicAuthRequestInterceptor  implements RequestInterceptor {    public FeignBasicAuthRequestInterceptor() {
    }    @Override
    public void apply(RequestTemplate template) {
        HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
        String token = (String)request.getSession().getAttribute("Authorization");
        template.header("Authorization", token);
    }
}

@Configurationpublic class FeignConfiguration {    /**
     * 创建Feign请求拦截器,在发送请求前设置认证的token,各个微服务将token设置到环境变量中来达到通用
     * @return
     */
    @Bean
    public FeignBasicAuthRequestInterceptor basicAuthRequestInterceptor() {        return new FeignBasicAuthRequestInterceptor();
    }    /**
     * feigin 日志配置
     *
     * @return
     */
    @Bean
    public Logger.Level feignLoggerLevel() {        return feign.Logger.Level.FULL;
    }
}


查看完整回答
反对 回复 2018-10-24
  • 1 回答
  • 0 关注
  • 1644 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信