我正在运行本地REST-API。当我用Postman测试它时,我得到以下结果:
当我对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);
});
});
问题:第二个请求失败并返回权限错误。
问题是休息服务器上的设置。获取JWT和数据请求之间存在最小延迟。