【发布时间】:2020-08-24 17:31:02
【问题描述】:
我有一个项目分为两层。后端使用 Spring Boot 开发,由 Sprint security 和 JWT 保护,前端使用 Vue.js 开发,使用 Axios 库进行层间通信。
我正确接收到“Bearer token”身份验证,并且所有身份验证过程都正确完成。当我尝试发送带有令牌标头的请求以访问内容但令牌未发送时出现此问题,并且 Spring 引导返回 null 而没有内容。
这里是代码
getOffers: function () {
if (localStorage.getItem("userSession")) {
this.aux = JSON.parse(localStorage.getItem("userSession"));
this.token = this.aux.token;
this.tokenHeader = "Bearer "+this.token;
alert(this.tokenHeader)
};
console.log(`Bearer ${this.token}`)
axios.
get('http://localhost:8080/api/v1/offer', {'Authorization' : `Bearer ${this.token}`})
.then(response => {
console.log(response);
this.offers = response.data
}).catch(e => console.log(e))
}
P.S:当我在 Postman 中发出请求时,它可以正常工作并返回所需的对象。这是一个邮递员的例子: postman
【问题讨论】:
-
欢迎使用 stackoverflow。参观并获得您的第一个徽章-stackoverflow.com/tour
标签: spring-boot vue.js axios jwt