Axios在POST请求中返回401 [关闭]
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Axios在POST请求中返回401 [关闭]相关的知识,希望对你有一定的参考价值。
postDate = async () => {
const token = await AsyncStorage.getItem('access');
const access = 'Bearer ' + token;
axios.get(`http://laundry.test/api/auth/user`, {
headers: {
'Authorization': access,
}
}).then(res => {
const id = res.data.id;
setID(id);
}),
axios.post('http://laundry.test/api/auth/saveDate',
{
headers: {
'Authorization': access,
},
user_id: { id }, // trying to post this
date: await AsyncStorage.getItem('Date'), // trying to post this
}).then(res => {
console.log(res);
})
}
postDate = async () => {
const token = await AsyncStorage.getItem('access');
const access = 'Bearer ' + token;
axios.get(`http://laundry.test/api/auth/user`, {
headers: {
'Authorization': access,
}
}).then(res => {
const id = res.data.id;
setID(id);
}),
axios.post('http://laundry.test/api/auth/saveDate',
{
user_id: { id },
date: await AsyncStorage.getItem('Date'),
},
{
headers: {
'Authorization': access,
}
}).then(res => {
console.log(res);
})
}
以上是关于Axios在POST请求中返回401 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
Axios 发布请求适用于 Postman,但不适用于浏览器(它返回“错误 401-未授权”)
Axios GET 请求 Spotify API 返回 401