简体   繁体   English

在axios的标头中发送令牌时收到500错误代码和跨源

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

While I am calling get request in axios I am sending the token in header but token is displaying null in backend and giving error like 500 and cross origin error: 当我在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
          }
        })

this is error showing in console; 这是控制台中显示的错误;

OPTIONS http://xxxx:8080/entity-services/api/v1/user?isActive=true 500 Access to XMLHttpRequest at ' http://xxxx:8080/entity-services/api/v1/user?isActive=true ' from origin ' http://localhost:3000 ' has been blocked by CORS policy: Response to preflight request doesn't pass access contro 选项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策略阻止:对预检请求的响应未通过访问权限

This is because of Cross Origin Resource sharing. 这是因为跨源资源共享。 Just add following header in you response headers in you backend and it should work: 只需在后端的响应标头中添加以下标头,它就可以工作:

Access-Control-Allow-Origin: *

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM