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 throws a Network Request Failed error. I am using Android Emulator that comes with Android Studio. I have read almost all related answers but none of them seem to help me. I am working with Android 6.0 API level 23. The code and the error screenshots are attached below. And yes, I have enabled internet permission in manifest file.
handleSignup(event) {
Alert.alert("Sigup was pressed!");
fetch(' https://example.com/v1/users/register', {
method: 'post',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
},
body: JSON.stringify({
email: this.state.email,
password: this.state.password,
firstName: this.state.firstName,
lastName: this.state.lastName,
mobile: this.state.mobile
})
})
.then(response => {
// console.log('sss', response);
return response.json();
})
.catch((error) => {
console.error(error);
});
}