Background: I'm using react-native and rails and developing on a Kindle Fire HD tablet. When I use fetch to try to connect to the rails server running locally on my macbook, I get the following error.
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (index.android.bundle:12432)
at XMLHttpRequest.dispatchEvent (index.android.bundle:15169)
at XMLHttpRequest.setReadyState (index.android.bundle:14953)
at XMLHttpRequest.__didCompleteResponse (index.android.bundle:14809)
at index.android.bundle:14904
at RCTDeviceEventEmitter.emit (index.android.bundle:5866)
at MessageQueue.__callFunction (index.android.bundle:4838)
at index.android.bundle:4654
at MessageQueue.__guard (index.android.bundle:4809)
at MessageQueue.callFunctionReturnFlushedQueue (index.android.bundle:4653)
Here is the fetch request.
fetch('https://192.168.X.X:8080/api/collections', {
method: 'GET',
body: null,
})
.then((response) => response.json())
.then((responseJson) => {
console.log(responseJson)
return success(responseJson);
})
.catch((err) => {
errors(err);
});
Searching around, most of the suggestions say to replace the localhost/127.0.0.1 to the ip of the server. But that seems to not have helped.
Make sure your Mac port is open, it isn't by default. Also make sure the firewall s either off or allowing the connections through.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.