【发布时间】:2018-07-05 14:26:39
【问题描述】:
当我在地址“http://localhost:8080/clients”上执行获取请求时,我需要帮助以在标头中包含令牌。
现在我收到这条消息“HTTP 403 Forbidden”。
授权令牌 1234abcd
function getAllClients() {
const myHeaders = new Headers();
myHeaders.append('Content-Type', 'application/json');
return fetch('http://localhost:8080/clients', {
method: 'GET',
mode: 'no-cors',
headers: myHeaders,
})
.then(response => response.json())
.then((user) => {
console.log(user.name);
console.log(user.location);
})
.catch((error) => {
console.error(error);
});
}
getAllClients();
【问题讨论】:
-
您是否尝试在标头中附加令牌?提供有关您创建的 API 以及如何调用令牌的更多信息。
标签: javascript fetch fetch-api