React Native-FETCH响应为空-API状态500-POST调用

时间:2019-12-30 22:23:21

标签: react-native express

    signIn = () => { 
    //post data to express backend
    fetch('http://10.0.2.2:3000/api/v1/auth', {
        method: 'POST',
            header: {
            'Accept': 'application/json',
            'Content-Type': 'application/json',
        },

        body: `login=${this.state.login}&password=${this.state.password}`
    })

    .then((response) => response.json())
    .then ((res => {

        if(res.status === 200) {
           AsyncStorage.setItem('user', this.state.login);
           this.props.navigation.navigate('Authorized')
        } else {
            alert("Response:", res);
        }
    }))
    .done();
}

以上是针对React-Native的。下面是快速后端:

router.post('/', function(req,res){
var login= req.body.login;
var password = req.body.password;
var sql = `SELECT * FROM users WHERE username = '${login}' OR number = '${login}' AND password = ${password}`
db.query(sql, function (err, rows, fields) {
    if (err) {
        res.status(500).send({error: 'Something went wrong!'})
    } else {
        if(rows.length > 0) {
            if (rows[0].password == password) {
                res.status(200).send({success: 'Login Successful'})
            }
        }  else {
        res.status(404).send({error: 'Email or Password does not match!'})
    }
    }
})

});

我认为没有任何回应,或者还有其他一些我现在无法解决的问题。寻求帮助

0 个答案:

没有答案