【问题标题】:Error using Axios on react-native network error在 react-native 网络错误上使用 Axios 时出错
【发布时间】:2018-08-31 00:16:53
【问题描述】:

我在我的代码中使用 Axios,当我尝试为 API 发送数据时,控制台中会出现一条消息“错误网络错误”

这是我的代码:

  salvar() {

   axios.post('http://easypasse.com.br/gestao/wsCadastrar.php',
   { nome: this.state.nome, cpf: this.state.cpf, senha: this.state.senha, method: 'app-set-usuario', "plataforma": 'ios'},
   {headers: {'Content-Type': 'application/json'}
   })
   .then(function(response){
   console.log(response)
   })
  .catch(function(error) {
   console.log('Erro ' + error.message);
  });
}

这是我的 info.plist

为什么会出现这个问题?

【问题讨论】:

    标签: ios react-native axios


    【解决方案1】:

    这可能是因为您使用的是 http 而不是 https。

    根据下面的讨论,还可以尝试关闭所有内容并清除 RN 缓存。

    【讨论】:

    • 即使 info.plist 设置为“应用程序传输安全设置”?
    • 哦,那应该没问题。我也有这个,我不得不关闭我的模拟器 + react-native-debugger,清除 react-native 缓存,我认为这有帮助。我的 api 密钥在某些时候也丢失了,但我认为这是一个不相关的问题。一个 xcode 项目清理也永远不会受到伤害
    • 你有什么建议?关闭所有内容(Xcode 和 React-Native)并再次打开?
    • 1.检查您的帖子是否正确(使用邮递员并准确传递您要发送的内容) 2. 关闭所有内容,清除 RN 缓存
    • 我已经拿到了。我关闭所有应用程序,Xcode 结束 React-Native,再次重新打开并工作。
    猜你喜欢
    • 2020-04-23
    • 2021-07-07
    • 2022-09-30
    • 2020-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-12-29
    • 2021-08-21
    • 2021-05-25
    相关资源
    最近更新 更多