ios - 在 react native 应用程序中使用提取时出错

标签 ios react-native fetch

我在 React Native 应用程序中使用以下获取调用:

fetch(apiUrls.signInUrl, {
  method: 'POST',
  headers: {
    'Accept': 'application/json',
    'Content-Type': 'application/json',
  },
  body: JSON.stringify({
    user: {
      email: username,
      password: password,
    }
  })
})
.then(response => {
  response.json().then(responseJson => {
    dispatch(AccountActions.loginResponse(username, password, responseJson.token, response.status));
    dispatch(CardActions.getCards(username, responseJson.token));
  });
})
.catch(err => {
  console.error(err);
});

获取调用失败并显示以下错误屏幕。有什么帮助吗? enter image description here

最佳答案

在 IOS 中,默认情况下禁用 http 连接。所以你必须启用它。虽然不推荐,但对于 Debug模式应该没问题。

步骤如下: 1. 你在 Xcode 中进入你的 iOS 项目的 Info.plist 文件

  1. 将允许任意加载更改为"is" enter image description here

  2. 如果您不想启用“允许任意加载”选项,您也可以选择将您的可信主机添加到异常(exception)域

祝你好运!

关于ios - 在 react native 应用程序中使用提取时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39303063/

相关文章:

ios - imageview 始终位于 tableview 中心

ios - 如何在 viewDidLoad 之前初始化 UITableView?

android - react-native-keyboard-aware-scroll-view 无法正常工作

git - Bitbake (Yocto) git fetch URI 认证

php - 获取行并分解 - PHP mySQL

ios - 位置管理器对 20 个区域的限制是否意味着总共 20 个地理围栏和信标区域?

ios - 将数组数据从 ViewController 传递到 TableView

javascript - React Native FlatList : Select all Items and run 'OnPress'

react-native - 安装 react-native-async-storage 后开 Jest 测试失败

php - eZPublish 使用 php 获取内容