javascript - react native 'unexpected url'错误

标签 javascript android react-native axios expo

我正在使用 axios 将数据发布到我的本地服务器。

    _handleBarCodeRead = data => {
    axios.post('192.168.0.100/getitem', {
        id: data.data,

      })
      .then(function (response) {
        console.log(response);
      })
      .catch(function (error) {
        console.log(error);
      });
  };

数据在事件中发布

       <BarCodeScanner
          torchMode="off"
          onBarCodeRead={this._handleBarCodeRead}

        />

我收到错误“意外的 url 192.168.0.100/getitem” enter image description here

最佳答案

尝试通过添加前缀(使用 http 或 https)'http://使 URL 成为相对 ('/getitem')正确绝对 URL 192.168.0.100/getitem'

    _handleBarCodeRead = data => {
axios.post('http://192.168.0.100/getitem', {
    id: data.data,

  })
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

};

关于javascript - react native 'unexpected url'错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49031641/

相关文章:

javascript - subview 在 angular-ui-router 中不起作用

javascript - 在html中用javascript解析xml

javascript - 如何在该类中的函数内的类中设置 this.var?

java - 如何通过代码恢复生命周期状态?

Android - 将 URL 转换为文件

reactjs - 在 React Native 中渲染逗号分隔的值字符串

javascript - Body-Parser 不读取请求正文

android - 如何使用android设备将捕获图像上传到mysql服务器

javascript - 您可以将 getstream.io js 客户端与 React Native 一起使用,而不是 React-Native-activity-feed 吗?

react-native - 如何避免 createStackNavigator 崩溃 react native 应用程序?