React Native fetch TypeError:网络请求失败

时间:2017-10-07 17:25:20

标签: reactjs react-native fetch

我正在创建我的第一个rect本机应用。使用OS11 Iphone 6模拟器在OSX上运行。在https fetch call中获得以下错误。使用XCode 9。

ExceptionsManager.js:73 TypeError: Network request failed
    at XMLHttpRequest.xhr.onerror (fetch.js:441)
    at XMLHttpRequest.dispatchEvent (event-target.js:172)
    at XMLHttpRequest.setReadyState (XMLHttpRequest.js:548)
    at XMLHttpRequest.__didCompleteResponse (XMLHttpRequest.js:381)
    at XMLHttpRequest.js:487
    at RCTDeviceEventEmitter.emit (EventEmitter.js:181)
    at MessageQueue.__callFunction (MessageQueue.js:306)
    at MessageQueue.js:108
    at MessageQueue.__guard (MessageQueue.js:269)
    at MessageQueue.callFunctionReturnFlushedQueue (MessageQueue.js:107)

反应组件获取代码。 (这是来自react-native官方示例的示例代码)

   getMoviesFromApiAsync() {
        return fetch('https://facebook.github.io/react-native/movies.json')
            .then((response) => response.json())
            .then((responseJson) => {
                return responseJson.movies;
            })
            .catch((error) => {
                console.error(error);
            });
    }

我是否真的需要更新info.pllist以启用允许任意负载?我试过启用它一次但没有用。

的package.json { "name": "rnstarter", "version": "0.0.1", "private": true, "scripts": { "start": "node node_modules/react-native/local-cli/cli.js start", "test": "jest" }, "dependencies": { "react": "16.0.0-beta.5", "react-native": "^0.49.1" }, "devDependencies": { "babel-jest": "21.2.0", "babel-preset-react-native": "4.0.0", "jest": "21.2.1", "react-test-renderer": "16.0.0-beta.5" }, "jest": { "preset": "react-native" } }

1 个答案:

答案 0 :(得分:0)

在与雇主的网络断开连接之后,它开始工作了。奇怪的是,即使我连接到雇主的网络,我也可以使用我的浏览器访问facebook api。