Recently I have been facing "Network request failed" issue with the React Native Android app on physical devices. Strangely it works fine on the Emulator but fails only on physical devices be it Android 7, 8, etc. I have upgraded Android Studio to latest, React Native to latest, but still getting this issue.
fetch('https://jsonplaceholder.typicode.com/todos/1')
.then(response => response.json())
.then(json => console.log("MYJSONRESPONSE", json))
.catch(e => console.log("ERRORRESP", e))
Above is a simple API call, even if I put any other working API URL it will still show the same Network error. Some of the other sample APIs I tried https://dummyapi.io/data/v1/user?limit=10 https://reqres.in/api/users?page=2
[TypeError: Network request failed]
This happens on a fresh react native project as well even on 0.62 or 0.65
"dependencies": {
"react": "17.0.2",
"react-native": "0.65.1"
}
Anybody with any solution for this issue?
2
Answers
the issue has been resolved and the solution was,
(optionally) setting up network security group for the system/custom domains.
Thank you everyone for your suggestions.
It might work if you add a www, like
https://www.jsonplaceholder.typicode.com/todos/1