簡體   English   中英

在axios的標頭中發送令牌時收到500錯誤代碼和跨源

[英]getting 500 error code and cross origin while sending token in header in axios

當我在axios調用get請求時,我在標頭中發送令牌,但令牌在后端顯示為null ,並給出類似500的錯誤和跨源錯誤:

 var token = localStorage.getItem('token');

 axios.get("http://x.x.x.x:8080/entity-services/api/v1/user?isActive=true", {headers: {
            "auth_key" : token
          }
        })

這是控制台中顯示的錯誤;

選項http:// xxxx:8080 / entity-services / api / v1 / user?isActive = true 500訪問位於' http:// xxxx:8080 / entity-services / api / v1 / user?isActive = true '的XMLHttpRequest來自源' http:// localhost:3000 '的信息已被CORS策略阻止:對預檢請求的響應未通過訪問權限

這是因為跨源資源共享。 只需在后端的響應標頭中添加以下標頭,它就可以工作:

Access-Control-Allow-Origin: *

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM