React-Native提取,networking请求失败。 不使用本地主机

我有一个应用程序,即时通讯使用获取authentication用户。 它直到前几天都在工作,我什么都没有改变。 刚刚从反应0.27升级到0.28,不抓取不工作。

我已经search了近2天,我已经阅读了几乎所有的问题在stackoverflow。 大多数用户试图从本地主机获取某些东西,当他们将其更改为实际的IP地址时,他们就可以正常工作。 但即时通讯不从本地提取任何东西,也是我的代码曾经工作。

这里是我的代码:

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(); 

我试图做一些新的项目,简单的,只是使用了一个简单的获取示例来教程,它给了同样的错误。 我试图打开我的网站,即时尝试连接到它,通过浏览器在模拟器,它的工作原理,但似乎通过我的应用程序无法连接到任何网站/ IP。 它在Chrome控制台中给出了这个错误:

 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) 

实际上,我在这里遇到与此用户相同的问题: React-nativenetworking请求总是失败

更新: xcode的info.plist

任何帮助将不胜感激!

你应该看看这个链接: https : //github.com/facebook/react-native/issues/8118

看起来问题出现在React Native 0.28中。 解决方法是在React创build的ios> build文件夹中find的info.plist文件中“允许任意加载”。

如果你打开xcode中的整个ios文件夹,然后打开这个info.plist文件,你可以创build一个新的密钥允许任意负载,它应该解决您的问题。

允许任意负载