React-Native fetch, network request failed. do not use localhost

I have an application that im uses fetch to authenticate a user. It worked until a few days ago, and I do not change anything. just updated from reaction 0.27 to 0.28, and not sampling does not work.

I searched for almost 2 days and I read almost all the questions on stackoverflow. most users try to extract something from localhost, and when they change it to the actual IP address, they make it work. but I didn’t get anything from localhost, my code was also used.

here is my code:

fetch('http://somesite.com/app/connect', { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json', 'language':'en-US', 'Authorization': 'Bearer ' + access_token, }, body: JSON.stringify({ uid: uid, refresh_token: refresh_token, token: access_token, device: device_id, device_name: device_name, }) }) .then((response) => response.json()) .then((responseData) => { console.log(JSON.stringify(responseData.body)) }) .catch((err)=> { console.log('Some errors occured'); console.log(err); }) .done(); 

I tried to make some new projects, just, just used a simple example of learning lessons, it gave the same error. I tried to open my site, which I am trying to connect to it, through a browser in the emulator, it works, but it seems that through my application I can’t connect to any website / ip. it gives this error in chrome console:

 TypeError: Network request failed at XMLHttpRequest.xhr.onerror (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:28193:8) at XMLHttpRequest.dispatchEvent (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:14591:15) at XMLHttpRequest.setReadyState (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29573:6) at XMLHttpRequest.__didCompleteResponse (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29431:6) at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:29506:52 at RCTDeviceEventEmitter.emit (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:13428:23) at MessageQueue.__callFunction (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11999:23) at http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11906:8 at guard (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11857:1) at MessageQueue.callFunctionReturnFlushedQueue (http://localhost:8081/index.ios.bundle?platform=ios&dev=true&hot=true:11905:1) 

I actually have the same problem as this user here: An invalid React network request always fails

UPDATE: info.plist from xcode

Any help would be appreciated!

+29
javascript ios fetch reactjs react-native
Jun 28 '16 at 13:12
source share
1 answer

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

React Native 0.28 seems to be having a problem. The solution is to "Allow arbitrary loads" in the info.plist file found in the ios> build folder created by React.

If you open the entire ios folder in xcode, then open this info.plist file, you can create a new key to resolve arbitrary loads, and it should fix your problem.

Allow arbitrary loads

+61
Jul 06 '16 at 8:28
source share
β€” -



All Articles