首页 > 解决方案 > 在 react-native 网络错误上使用 Axios 时出错

问题描述

我在我的代码中使用 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 信息列表

为什么会出现这个问题?

标签: iosreact-nativeaxios

解决方案


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

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


推荐阅读