** I am trying to build a registration page in react-native which sends the data to an API. Whenever I try filling the form and sending the request, the emulator works fine but real android device shows a Network Request Failed error. I have read almost all related answers but none of them seem to help me. I am working with Android 7.0 API level 24. The code attached below.I have enabled internet permission in manifest file.**
fetchRegister(){
var object = {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body:JSON.stringify( {
"phone_number": this.state.contactNumber,
"password": this.state.password,
})
};
fetch('https://example.com/chatapp/web/registrations.php',object)
.then((response) => response.json())
.then((responseText) => {
if(responseText.status == '200'){
this.setState({
registrationSuccessfull:true
})
var { navigate} = this.props.navigation;
setTimeout(() => {
navigate("Login",{screen: "Login"});
}, 3000);
}else if(responseText.status == '405'){
this.setState({
registeredAlready:true,
});
}
})
.catch((error) => {
console.error(error);
});
}