解析失败[TypeError:网络请求失败] Expo,react-native

时间:2019-07-09 13:36:20

标签: react-native http https fetch expo

我制作了一些小应用程序,可以读取条形码并通过API发送数据。

示例:

handleBarCodeScanned = ({ type, data }) => {

    alert(`Bar code with type ${type} and data ${data} has been scanned! and the phone is ${this.state.maci`);

    var BarCodeScannedInApp = 'http://localhost:50474/api/ScanPart?PartBarCode=' + data + "&StationName=" + this.state.maci;
    fetch(BarCodeScannedInApp)
      .then(response => response.json())

    .catch(error => console.log('parsing failed', error))
  };

当代码尝试执行Fetch时,会引发异常“解析失败[TypeError:网络请求失败]”

  • 试图将LocalHost更改为我的实际IP地址,但这并没有帮助我。
app.json:
{
  "expo": {
    "name": "my-test-scan",
    "slug": "my-test-scan",
    "privacy": "public",
    "sdkVersion": "33.0.0",
    "platforms": [
      "ios",
      "android",
      "web"
    ],
    "version": "1.0.0",
    "orientation": "portrait",
    "icon": "./assets/icon.png",
    "splash": {
      "image": "./assets/splash.png",
      "resizeMode": "contain",
      "backgroundColor": "#ffffff"
    },
    "updates": {
      "fallbackToCacheTimeout": 0
    },
    "assetBundlePatterns": [
      "**/*"
    ],
    "ios": {
      "supportsTablet": true
    }
  }
}

有什么建议吗?

0 个答案:

没有答案