【问题标题】:Network Request failed - React Native - android网络请求失败 - React Native - android
【发布时间】:2020-04-27 17:55:41
【问题描述】:

以下是我的获取代码:

return fetch('https://172.16.57.200:8080/cebip/financeProductList',{
        method: 'GET',
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json',
        }
      })
        .then((response) => response.json())
        .then((responseJson) => {
          alert("hi");
          console.log(responseJson);
        })
        .catch((error) => {
          alert("error");
          console.error(error);
        });

我在 android 中收到以下错误:

网络请求失败 - xhr.onerror 中的 node_modules\whatwg-fetch\dist\fetch.umd.js:473:29 - EventTarget.prototype.dispatchEvent 中的 node_modules\event-target-shim\dist\event-target-shim.js:818:39 - setReadyState 中的 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:574:29 - __didCompleteResponse 中的 node_modules\react-native\Libraries\Network\XMLHttpRequest.js:388:25 - node_modules\react-native\Libraries\vendor\emitter\EventEmitter.js:190:12 在发出 - __callFunction 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:436:47 - __guard$argument_0 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:26 - __guard 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:384:10 - __guard$argument_0 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:110:17 * [native code]:null in callFunctionReturnFlushedQueue

【问题讨论】:

    标签: react-native


    【解决方案1】:

    这个问题是用 SSL 报告的,如果你不需要 https 协议,那么你可以在 android 中使用 http,但你应该在清单中添加以下行。

    如果您使用 https,那么我建议您更改您的 SSL 证书以解决问题。

    【讨论】:

      【解决方案2】:

      我将自己服务器的端口更改为 19001,它对我有用。如果您正在开发自己的服务器,也许您应该尝试这种方式。希望对你有用

      【讨论】:

        【解决方案3】:

        我在使用本地 IP 的“https”时遇到了同样的错误,只需删除“s”即可解决 例如:'http://172.16.57.200:8080/cebip/financeProductList

        【讨论】:

          猜你喜欢
          • 2021-04-07
          • 1970-01-01
          • 2019-01-06
          • 1970-01-01
          • 2018-06-16
          • 2020-07-23
          • 2019-08-11
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多