亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

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 關注
  • 1745 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號