我正在尝试访问API,但收到错误代码401。我在POSTMAN上试用了我的端点,它工作得很好。
我可以在邮递员身上提供一个无记名的代币。
如果合适,这里是代码。
async function fetchData(){
const response = await fetch('http://192.168.3.143:4040/mmi-endpoints/v0/article/custom_query', {
method : "POST",
mode: "cors",
cache: "no-cache",
credentials: "include",
headers: {
"Content-Type" : "application/json"
}
})
const data = await response.json()
setData(data)
}发布于 2021-05-26 16:43:03
您可以将不记名标记添加到请求的头部。
const token = 'your-t0ken_xyz'
async function fetchData() {
const response = await fetch('http://192.168.3.143:4040/mmi-endpoints/v0/article/custom_query', {
method : "POST",
mode: "cors",
cache: "no-cache",
credentials: "include",
headers: {
"Content-Type" : "application/json",
"Authorization": `Bearer ${token}`
}
})
const data = await response.json()
setData(data)
}https://stackoverflow.com/questions/67700761
复制相似问题