React-Native fetch, Network request failed. not using localhost React-Native fetch, Network request failed. not using localhost reactjs reactjs

React-Native fetch, Network request failed. not using localhost


You should check out this link: https://github.com/facebook/react-native/issues/8118

Looks like the issue emerged in React Native 0.28. Solution is to "Allow Arbitrary Loads" in the info.plist file found in the ios>build folder that React creates.

If you open the entire ios folder in xcode, then open this info.plist file you can create a new key to Allow Arbitrary Loads and it should fix your issue.

Allow Arbitrary Loads


Set the info.plist doesn't work for me too. Trying to run on iOS.


This issue is the code is trying to fetch HTTP endpoint instead of HTTPS, which is not encouraged. If you are fetching from localhost server, an easy solution will be exposing your localhost server through a Ngrok https endpoint.

Steps:

  1. Download ngrok and run ngrok http 8081 from terminal/cmd, where you should change 8081 to your localhost service port.

  2. Ngrok will give you a https forwarding endpoint, simply use that to access your localhost server.