I am using a Django server, and a react native frontend (with expo).
I can access the server fine on my browser and with the iOS simulator (I use a Mac), however, on the android simulator, I get a network error, and it can’t connect to my server.
Here is the react native code that works fine:
componentDidMount = () => {
fetch("http://127.0.0.1:8000/api/events/?featured=true", {
method: "GET",
})
What am I doing wrong?
2
Answers
Replace the X's in the above code with your machine's IP-address.
Use 10.0.2.2 to access your actual machine for the android emulator.
when you use the emulator, localhost (127.0.0.1) refers to the device’s own loopback service, not the one on your machine as you may expect.