I have created a race native project and would like to fetch a php from my localhost (I'm using mamp).
I have tried the following but it doesn't seem to work.
I have been trying to run my project using Xcode as my simulator but keep getting the following message.
TypeError: Netword request failed
Below is my full code.
UserRegistrationFunction = () => {
const { UserName } = this.state;
const { UserEmail } = this.state;
const { UserPassword } = this.state;
fetch('http://{my-ip}:8888/user_registration.php', {
method: 'POST',
headers: {'Accept': 'application/json','Content-Type': 'application/json',
},
body: JSON.stringify({
name: UserName,
email: UserEmail,
password: UserPassword
})
}).then((response) => response.json())
.then((responseJson) => {
Alert.alert(responseJson);
}).catch((error) => {
console.error(error);
});
}