問題描述
我正在嘗試通過 Javascript 將授權(quán)令牌承載發(fā)送到 REST 端點,所以我這樣做:
I'm trying to send a Authorization Token Bearer through Javascript to a REST Endpoint, so i doing in this way:
我的端點在 SpringBoot 容器下運(yùn)行,所以我正在獲取 HttpServletRequest 并嘗試獲取 AUthorization Header 但始終為空:
My endpoint is running under a SpringBoot container, so i'm getting the HttpServletRequest and trying to get AUthorization Header but is always null:
編輯 1這是客戶端(瀏覽器)中的錯誤
Edit 1 This is the error in Client-Side (Browser
編輯 2為了在后端啟用 CORS,我在 spring 中使用了以下注釋:
Edit 2 To enable CORS in backend i'm using the following annotation with spring:
編輯 3我嘗試在我的過濾器中添加 CORS,但沒有成功:
Edit 3 I tried added the CORS in my Filter but no success:
推薦答案
您可以使用headers
鍵添加標(biāo)題
您需要在后端啟用 CORS
You need to enable CORS on backend
https://stackoverflow.com/a/32320294/5567387
這篇關(guān)于通過 Javascript 發(fā)送 Authorization Token Bearer的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!