在反应本机应用程序中使用提取时出错

Error while using fetch in react native app

我在 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);
});

提取调用失败,出现以下错误屏幕。有什么帮助吗?

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

步骤如下: 1. 您转到 Xcode

中 iOS 项目的 Info.plist 文件
  1. 将允许任意加载更改为 "YES"

  2. 如果您不想启用 "allow arbitrary loads" 选项

  3. ,您也可以选择将受信任的主机添加到例外域

祝你好运!