第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

HTTP狀態(tài)代碼401,即使我在請(qǐng)求中發(fā)送憑據(jù)

HTTP狀態(tài)代碼401,即使我在請(qǐng)求中發(fā)送憑據(jù)

aluckdog 2019-11-04 10:10:41
最近我已經(jīng)介紹了智威湯遜驗(yàn)證我的Springboot和基于Angualr2應(yīng)用。在There中,我嘗試通過在Angualr代碼中傳遞JWT令牌來(lái)發(fā)出POST請(qǐng)求save(jobId: number, taskId: number, note: Note) {   return this.http.post(environment.APIENDPOINT + '/jobs/' + jobId + '/tasks/' + taskId + '/notes', note, this.setHeaders()).map((response: Response) => response.json());}private setHeaders() {        // create authorization header with jwt token        let currentUser = JSON.parse(localStorage.getItem('currentUser'));        console.log("Current token---"+ currentUser.token);        if (currentUser && currentUser.token) {  let headers = new Headers();  headers.append('Content-Type', 'application/json');  headers.append('authorization','Bearer '+ currentUser.token);               let r = new RequestOptions({ headers: headers })   return r;        }    }但是在服務(wù)器端,它返回狀態(tài)碼401。問題是在Springboot端,它如下所示檢查授權(quán)標(biāo)頭,并返回nullString authToken = request.getHeader("authorization ");然后,我看了一眼請(qǐng)求頭,它具有在訪問控制請(qǐng)求報(bào)頭的授權(quán)頭下面。但是它對(duì)服務(wù)器端不可見。然后,我進(jìn)一步閱讀,發(fā)現(xiàn)這可能與CORS配置有關(guān)。所以我修改了我的CORS配置過濾器,使其具有addExposedHeader,如下所示@Beanpublic CorsFilter corsFilter() {    UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();    CorsConfiguration config = new CorsConfiguration();    config.setAllowCredentials(true);    config.addAllowedOrigin("*");    config.addAllowedHeader("*");    config.addExposedHeader("authorization");    config.addAllowedMethod("OPTIONS");    config.addAllowedMethod("GET");    config.addAllowedMethod("POST");    config.addAllowedMethod("PUT");    config.addAllowedMethod("DELETE");    //config.addExposedHeader("Content-Type");    source.registerCorsConfiguration("/**", config);    return new CorsFilter(source);}服務(wù)器仍然抱怨找不到授權(quán)頭。我在這里想念任何東西嗎?感謝您的幫助
查看完整描述

2 回答

  • 2 回答
  • 0 關(guān)注
  • 1007 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)