网络请求未能响应本机expo客户端

时间:2019-07-03 09:54:59

标签: react-native

网络请求失败

我尝试允许端口连接 由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
  ...

2 个答案:

答案 0 :(得分:0)

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

答案 1 :(得分:0)

首先,在笔记本电脑或PC中找到您的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客户端连接到本地服务器时,请使用http://localhost:8000而不是http://YourIPAddress:8000