[英]axios REST call with JWT
I am running a local REST-API. 我正在运行本地REST-API。 When I test it with Postman I get the following results:
当我用Postman测试它时,得到以下结果:
When I do the same with axios I get a permission error: 当我对axios执行相同操作时,出现权限错误:
axios
.request({
method: "get",
baseURL: "http://localhost/api/",
params: {
action: "login",
username: "user",
password: "pass"
}
})
.then(function(res) {
const token = res.data.JWT; //token is correct
axios
.get(
"http://localhost/api/index.php?action=list&object=media",
{
headers: {
"X-Authorization": "Bearer " + token
}
}
)
.then(function(res) {
console.log(res);
});
});
The problem: The second request fails and returns a permission error. 问题:第二个请求失败,并返回权限错误。
Screenshot1: Error in console 屏幕截图1:控制台错误
The problem was a setting on the rest server. 问题是其余服务器上的设置。 There was a minimum delay between getting JWT and data request.
在获取JWT和数据请求之间有最小的延迟。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.