![](/img/trans.png)
[英]JWT authentication with spring and angular with null header
[英]Angular 2 jwt authentication header does not work
我的jwt身份驗證出現問題。
我試圖從我的rest api獲取模板列表,但是當我嘗試訪問標頭'Authorization'時,該值為null。 這是我的代碼:
loadTemplates(): Observable<Template[]> {
const headers = new Headers({'Authorization': this.authService.getPrefix() + this.authService.getLocalToken()})
return this.httpService.post(this.baseURL + 'api/templates/short', {headers: headers})
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error));
}
設置了前綴和令牌,在控制台中登錄它們時可以看到它們。
該問題是,當我在Chrome的開發者控制台中查看時,可以看到Access-Control-Request-Headers:授權
但在后端它為null。 (試圖記錄標頭“ Authorization”的值)
當我嘗試通過Postman訪問后端時,它確實起作用。 具有相同的前綴+令牌。
我的猜測是,您忘記了在服務器端處理所謂的“預檢”請求。 嘗試添加類似此過濾器的內容 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.