【问题标题】:network request failed in react native expo client网络请求在反应本机博览会客户端中失败
【发布时间】:2020-09-21 17:45:15
【问题描述】:

网络请求失败

我已尝试允许端口连接 通过 sudo ufw 允许任何端口命令,但它没有帮助

fetch('http://192.XXXXXX//form/user_registration.php',
        {
            method: 'POST',
            headers:
            {
                'Accept': 'application/json',
                'Content-Type': 'application/json',
            },

网络请求失败

堆栈跟踪:

node_modules/react-native/Libraries/vendor/core/whatwg-fetch.js:504:29 in onerror
  node_modules/event-target-shim/lib/event-target.js:172:43 in dispatchEvent
  node_modules/react-native/Libraries/Network/XMLHttpRequest.js:580:29 in setReadyState
  node_modules/react-native/Libraries/Network/XMLHttpRequest.js:394:25 in __didCompleteResponse
  node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:190:12 in emit
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:366:47 in __callFunction
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:106:26 in <unknown>
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:314:10 in __guard
  node_modules/react-native/Libraries/BatchedBridge/MessageQueue.js:105:17 in callFunctionReturnFlushedQueue
  ...

【问题讨论】:

标签: react-native


【解决方案1】:

首先,在您的笔记本电脑或电脑中找到您的 IP 地址:

Mac:https://osxdaily.com/2010/11/21/find-ip-address-mac/

Windows:https://www.whatismyip.com/how-to-get-your-local-ip-address-on-windows-10/

Linux:https://opensource.com/article/18/5/how-find-ip-address-linux

然后,当您尝试将 expo 客户端连接到 localhost 服务器时,不要使用 http://localhost:8000,而是使用 http://YourIPAddress:8000

【讨论】:

    【解决方案2】:

    我通过在我的电脑和手机上使用相同的连接解决了这个问题 在 USB tathering 的帮助下,我在两边都获得了相同的 ip,而且我也必须更改我的端口号,因为两个本地服务器不会相互冲突......

    【讨论】:

      猜你喜欢
      • 2019-09-16
      • 2019-08-19
      • 2018-03-01
      • 1970-01-01
      • 2019-02-09
      • 1970-01-01
      • 2020-04-28
      • 2021-04-12
      • 2022-01-22
      相关资源
      最近更新 更多