我知道有一些关于这个的答案,我都阅读了。但他们都没有帮助。 所以这是我的错误信息:
这是我的操作:
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/