React Native fetch()网络请求失败 [英] React Native fetch() Network Request Failed

查看:448
本文介绍了React Native fetch()网络请求失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用 react-native init (RN版本0.29.1)创建一个全新的项目时,将render方法中的fetch放入公共facebook演示影片API ,它会抛出网络请求失败。有一个非常无用的堆栈跟踪,我无法在chrome控制台中调试网络请求。这是我发送的fetch:

When I create a brand new project using react-native init (RN version 0.29.1) and put a fetch in the render method to the public facebook demo movie API, it throws a Network Request Failed. There is a very useless stack trace and I can't debug network requests in the chrome console. Here is the fetch I'm sending:

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


推荐答案

这里的问题是iOS不允许HTTP请求默认情况下,只有HTTPS。如果要启用HTTP请求,请将此添加到 info.plist

The problem here is that iOS does not allow HTTP requests by default, only HTTPS. If you want to enable HTTP requests add this to your info.plist:

<key>NSAppTransportSecurity</key>
<dict>
    <key>NSAllowsArbitraryLoads</key>
    <true/>
</dict>

这篇关于React Native fetch()网络请求失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆