你好,伙计们,
我在反应原生中发出了一个Http post请求我通过检查在调试器上收到了成功消息,但在我的警报上显示错误。我的问题是我在调试器中收到状态但在前面收到错误警告。请在我犯错的地方帮助我。我不知道为什么它会出现错误提示。我认为它是正确的。
CallSignIn()
{
try
{
let response = fetch('post url will be here',
{
method: 'POST',
headers:
{
'x-api-key': '1k1gdyaa7bdy', // this is example key but original token key have to pass
'Content-Type': 'application/json',
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
})
});
if (response.status > 200 && response.status < 300)
{
this.setState({showProgress: false})
let res=response.status;
Alert.alert(res);
}
else
{
let error;
Alert.alert("Error :",error);
this.setState({showProgress: false})
}
} catch(e)
{
Alert.alert("Error:",error);
this.setState({showProgress: false})
}
}
onSignInPress()
{
const { email, password } = this.state;
if (this.isValid())
{
this.setState({showProgress: true})
NetInfo.isConnected.fetch().done((isConnected) =>
{
if ( isConnected )
{
this.CallSignIn();
}
else
{
Alert.alert("Internet is Offline")
}
});
}
}