C. Parakh
C. Parakh

Reputation: 79

Network Request failed when trying to fetch data from a localhost

My code works fine when I fetch data from "http://www3.septa.org/beta/TransitView/23"

But while I try to fetch data from "http://localhost:3000/allDetails" I get an error in react-native saying:

"Network Request Failed".

I can get the data from "http://localhost:3000/allDetails" using Google Chrome but not when I fetch it in my react-native code.

I also tried to fetch data using "http://127.0.0.1:3000/allDetails" still same error.

Upvotes: 1

Views: 938

Answers (1)

Mμ.
Mμ.

Reputation: 8542

I ran into this problem before. 127.0.0.1 will point to the emulator itself in your computer where the server is currently running. Try replacing 127.0.0.1 with 10.0.2.2 if you are on AVD or 10.0.3.2 if you are on Genymotion or with your computer's actual IP address.

Upvotes: 1

Related Questions