Quantcast
Channel: Active questions tagged react-native+ios - Stack Overflow
Viewing all articles
Browse latest Browse all 16750

How to fetch localhost in react native?

$
0
0

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.

fetch('http://(my_ip):8888/user_registration.php',

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);
        });
}

Viewing all articles
Browse latest Browse all 16750

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>