我从API获取令牌,但不幸的是我的API返回了400个错误的请求。我已经通过Postman检查了我的api,并且在那儿工作正常。请让我知道解决方案或任何错误。
async componentWillMount(){
axios.post('http://api.myapiurl.com/token', {
grant_type: 'PASSWORD',
username: 'MY_USERNAME',
password: 'MY_PASSWORD'
}, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
}
}).then(response => {
console.log(response.data)
}).catch(err => console.log("api Erorr: ", err.message))
}
以下回应错误
请求失败,状态码为400-createError中的node_modules \ axios \ lib \ core \ createError.js:16:24-结算中的node_modules \ axios \ lib \ core \ settle.js:18:6-...还有10个堆栈帧从框架内部
通过使用解决QueryString.stringify()
。我只是将身体传递QueryString.stringify()
如下:
axios.post('http://api.apiurl.com/token', QueryString.stringify({
grant_type: 'MY_GRANT_TYPE',
username: 'MY_USERNAME',
password: 'MY_PASSWORD'
}), {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
}
}).then(response => {
console.log(response.data)
}).catch(err => console.log("api Erorr: ", err.response))
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句