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

标签 react-native redux react-redux axios

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

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/

相关文章:

ios - 设备发布时应用程序安装失败

react-native - 在 React Native Expo 应用程序中解码没有 key 的 JWT token

javascript - React-router-dom 重定向不适用于 withRouter HOC (react-redux)

android - Google Play 为我的 React Native 应用程序发出的调用/短信许可最终警告电子邮件

android - Reactnative $JAVA_HOME 路径错误

reactjs - 组合来自 2 个不同项目的 2 个 redux 存储

javascript - 如何在大型规范化 Redux 存储中组织 reducer

reactjs - 如何使用 React、React Intl 和 Redux 翻译操作中的 (i18n) 错误消息?

javascript - 使用react-virtualized-select时出错

javascript - 在 JavaScript 函数中访问 Redux 存储