React Native Fetch Remote Http request throws Network Request Failed (On Android Device)

componentDidMount() {
const url = (Remote Http URL);
this.setState({ loading: true });
fetch(url)
.then(res => res.json())
.then(res => {
this.setState(
{
loading: false,
error: res.error || null,
data1: res
},
()=> {
console.log(res);
}
);
})
.catch(error => {
this.setState({ error, loading: false }, () => {
console.log(error);
});
});
}

I am trying to access Remote HTTP Api on my local machine. The API is working perfectly on Postmant as well as on Chrome in my local machine. But When make Fetch call using Expo React Native Fetch I am getting the following error:

Network request failed

  • node_modules\whatwg-fetch\dist\fetch.umd.js:473:29 in xhr.onerror
  • node_modules\event-target-shim\dist\event-target-shim.js:818:39 in EventTarget.prototype.dispatchEvent
  • node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 in setReadyState
  • node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 in __didCompleteResponse
  • node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 in emit
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 in __callFunction
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 in __guard$argument_0
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 in __guard
  • node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 in __guard$argument_0
  • [native code]:null in callFunctionReturnFlushedQueue

For your information I am trying to run the app on an Latest Android Device.

Use IP address instead of local host.

Thanks.
Finally I solve this issue. The problem is with the networking. My mobile device and the API hosted server was not in the same network.

I have the exact error message, would you please tell me how?

thanks!

Can you please explain the scenario you are facing.

I was getting the same error message you got when using localhost urls, i solved this using ngrok

thank you for your reply.

@aaburahma
Great!

Brother please tell me how to solve this problem I connect my laptop and mobile device both on same wifi network and then use laptop ip address in base url file but it failed to fetching data stored in redux store please resolve my problem

@aaburahma @ankurvishnoi123 please tell how to solve the problem

Plese check my answer. Use IP address instead of local host.

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.