gpt4 book ai didi

reactjs - Axios 发布请求在 React Native 中不起作用

转载 作者:行者123 更新时间:2023-12-04 15:37:41 27 4
gpt4 key购买 nike

我从 API 获取 token ,但不幸的是我的 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))
}

捕获错误

Request failed with status code 400

最佳答案

自己用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))

关于reactjs - Axios 发布请求在 React Native 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59194579/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com