Setheroni
Setheroni

Reputation: 145

React-native fetch fails with "Network request failed" when trying to hit remote server

I'm running a back-end server on an AWS EC2 and when I try to make requests with fetch, it just says Network request failed. I have tried a billion things tonight, I even bought a domain and set up ssl because other issues on here pointed to that being the problem, that didn't work though. Fetch works totally fine locally, but pointing to my server on AWS it doesn't. If I log the URL I'm about to fetch and paste it in my browser it works as it should.

Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:474: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

The error in fetch.umd.js:474:29 is : Event { "isTrusted": false, }

Upvotes: 1

Views: 996

Answers (2)

Setheroni
Setheroni

Reputation: 145

My issue was SSL related. Just wasn't set up correctly with nginx

Upvotes: 0

amitpanday
amitpanday

Reputation: 96

I hope this will help you, put this in your manifest file under application tag

<application
 ....
 android:usesCleartextTraffic="true" 
/>

Upvotes: 1

Related Questions