Search code examples
mysqlreact-nativeuser-registration

React Native Login with Mysql database using fetch. getting : Network request failed error


so i'm trying to follow this tutorial for Registration : https://reactnativecode.com/react-native-user-registration-example-tutorial/#comment-878

i’m using WampServer on Windows 10. I did as mentioned.

I created a folder called “/react” under “C:\wamp64\www\react” and put the two .php files there . when i put “localhost/react” in my browser i can see the .php files .

i changed the URL to : ‘http://localhost/react/user_registration.php

But i’m still getting that error .. i’m not sure what i’m doing wrong here


Solution

  • This happens simply because react-native consider localhost as an URL but it doesn't have a domain :

    Solution

    On Windows =>

    Run [Ctrl] + R

    Then type : "cmd", press enter

    write "ipconfig" then press enter

    a list of IP configurations will show, copy the IP address besides "IPv4 Address", it's under "Ethernet adapter VirtualBox Host-Only Network #2:", it starts with 192.168.xxx.x

    on MAC =>

    http://osxdaily.com/2010/11/21/find-ip-address-mac/

    You will now need to replace the URL with this IP Address

    you will have this at the end : http://192.168.xxx.x/react/user_registration.php

    as you've seen, i have replaced localhost to the ip address taken from the CMD [i.e IPV4 Address]

    You can also use only free hosting website like Awardspace, 000Webhost to test your app on a real device. Use your local server or this ip address, you can't fetch the data from real device

    Hope this will help you! Franz