我是新来的反应。尝试发出“获取”请求并禁止获取 403 错误,“预检响应没有 HTTP 正常状态。”。在请求方法的网络选项卡中,而不是“获取”方法显示“选项”。可能是什么问题呢? Cors 已经打开,令牌有问题
let token = localStorage.getItem("token")
axios
.get("http://dev.*****************get-template", {
headers: {
Authorization: `Bearer + ${token}`,
},
})
.then(res => {
console.log("Success")
})
.catch(error => {
console.log(error)
})
这就是我保存令牌的方式。可能是我没有正确地将它保存在 localStorage 中?但是当 console.log 它显示正常
event.preventDefault()
const formdata = new FormData()
formdata.append("username", this.state.userLogin.email)
formdata.append("password", this.state.userLogin.password)
axios
.post("http://dev.****************/get-token", formdata)
.then(res => {
if (res.data) {
console.log(res.data)
localStorage.setItem("token", res.data.access_token)
localStorage.setItem("updToken", res.data.update_token)
this.props.history.push("/settings")
}
})
.catch(error => {
console.log(error)
})
原文由 Yerlan Yeszhanov 发布,翻译遵循 CC BY-SA 4.0 许可协议
我发现你的 Bearer 令牌有问题
你写它:
但它应该是:
完整的答案是: