gpt4 book ai didi

react-native - 可能未处理的 promise 拒绝/错误 : Request failed with status code 400

转载 作者:行者123 更新时间:2023-12-02 03:32:44 27 4
gpt4 key购买 nike

我知道有一些关于这个的答案,我都阅读了。但他们都没有帮助。所以这是我的错误信息:

Error message

这是我的操作:

export function registerUser(data){
const request = axios({
method: "POST",
url: `${REGISTER}${API_KEY}`,
data: {
email: data.email,
password: data.password,
},
headers:{
"Content-Type":"application/json"
}
}).then(response => response.data)

return {
type: "REGISTER_USER",
payload: request,
}

}

谢谢!

最佳答案

尝试获取用于调用 API 的库。

function registerUser(data){
return fetch(url, {
method: 'POST',
body: JSON.stringify(data),
headers:{
'Content-Type': 'application/json'
}
})
.then(res => res.json())
.then((apiResponse)=>{
console.log("api response", apiResponse)
return {
type: "REGISTER_USER",
api_response: apiResponse.data
}
})
.catch(function (error) {
return {
type: "REGISTER_USER",
api_response: {success: false}
}
})
}

调用上面的函数

let data = { 
email: "youremail@gmail.com,
password:"yourpassword"
}

registerUser(data).then((response)=>{
console.log(response)
})

关于react-native - 可能未处理的 promise 拒绝/错误 : Request failed with status code 400,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51321542/

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