Axios POST方法:网络错误-React Native

时间:2019-12-05 13:22:03

标签: javascript android reactjs react-native axios

当我从邮递员发送带有我的Google Cloud地址的请求时可以,但是从android studio / react-native / axios发送错误时。

  

[错误:网络错误]

这是我的代码:

constructor(props){
    super(props);
    this.state = {
      email: '',
      password: '',
      error: '',
      loading: false
    };
}

handleLoginUser(){
    const { email, password } = this.state;
    this.setState({ error: '', loading: true });

    axios.post("https://serverip/users/login",
        {
            'email': 'email',
            'password': 'password'
        },
        {
    headers: {
      'Accept': 'application/json',
      'Content-Type': 'application/json; charset=utf-8',
            },
        }
    )
    .then(response => {
        console.log(response);
        return response.json();})
    .then(data => {
        if (result.success){
            alert("Login successful");
        }
        else
            alert("Unable to Login");
        })
    .catch((error) => {
      console.log(error);
    });
}

感谢您的帮助。

0 个答案:

没有答案
相关问题