[英]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.