react-native - 错误:在带有 axios 的 react-native 中请求失败,状态码为 400
问题描述
axios({
method: 'POST',
url: `http://${base_url}/token`,
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
data: {
"Username": "admin@diginepal.com",
"Password": "password@123456",
"grant_type": "password"
}
})
.then(res => {
console.log(res)
})
.catch(err => {
console.log(err)
})
我收到错误:请求失败,状态码为 400。我在这里做错了什么?
解决方案
很好,您设法解决了,以供将来参考,如果您有 400 Bad Request 错误,我发现打印 error.response.data 以获取更有意义的错误消息非常有用。
axios.post('/').then(response => {
console.log(response.data);
}).catch(error => {
console.log(error.response.data);
});
推荐阅读
- javascript - 如何编译具有严格内存限制的打字稿
- javascript - 困惑 | 当 API 请求失败时 Redux saga 不会抛出任何错误
- python - 得到一个错误,模块 backports.lzma 不存在于它应该存在的文件中,但该模块安装在我的机器中。我该如何解决?
- javascript - 如何从像谷歌浏览器开发工具这样的网站中提取反应 js 代码?
- mysql - 分配为动态字段别名的“用户定义变量”错误
- sql - 如何在 T-SQL 中将一列的结果分成多列?
- python-3.x - 了解这个 Python 装饰器是如何工作的
- azure-api-management - API 管理通知参数 - 它们在哪里?
- python - 为多个文档组合词袋
- sql - SQL 子查询混淆