0
votes

Network request failed

I have tried allowing port to connect by sudo ufw allow to any port command but it is not helping

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

Network request failed

Stack trace:

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
not working i think the problem is not that the thing is my device cannot access the local server - somesh balani
instead of using localhost:port for the API address, use IP address of the server. - sachin mathew
it is the ip address of the nginx also i have changed the port and allow the ufw to open access to this port - somesh balani
did you tried opening url in a browser? - sachin mathew

2 Answers

1
votes

i solved this by having a same connection on my pc as well as my phone with the help of usb tathering i got the same ip on both the sides, also i have to change my port number too due to that both local servers will not conflict with each other...

0
votes

First, find your IP Address in your laptop or pc:

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

Then, instead of using http://localhost:8000 use http://YourIPAddress:8000 when you are trying to connect your expo client to your localhost server.