I'm new on React, and trying to get data from my server. But the result is 'Network Error'. I've try to change domain to https://randomuser.me/api/?results=5, and still error. But when I try to request to https://www.google.com or https://facebook.github.io/react-native/movies.json, the results is ok. I've opened site from my device browser, all site have no problem.
axios.get(`https://randomuser.me/api/?results=5`)
.then((result) => {
console.log(result.data);
}).catch(error => {
this.setState({error, loading: false, refreshing: false});
console.log(error.message);
console.log(error);
});
Info:
I'm using android emulator (NOX).
Both of domain (my server & randomuser.me) use Cloudflare.
Error :
Error: Network Error
at createError (C:\react-native\First\node_modules\axios\lib\core\settle.js:25)
at XMLHttpRequest.handleError (C:\react-native\First\node_modules\axios\lib\adapters\xhr.js:72)
at XMLHttpRequest.dispatchEvent (C:\react-native\First\node_modules\event-target-shim\lib\event-target.js:172)
at XMLHttpRequest.setReadyState (C:\react-native\First\node_modules\react-native\Libraries\Network\XMLHttpRequest.…:580)
at XMLHttpRequest.__didCompleteResponse (C:\react-native\First\node_modules\react-native\Libraries\Network\XMLHttpRequest.…:394)
at C:\react-native\First\node_modules\react-native\Libraries\Network\XMLHttpRequest.…:507
at RCTDeviceEventEmitter.emit (C:\react-native\First\node_modules\react-native\Libraries\vendor\emitter\EventEmi…:190)
at MessageQueue.__callFunction (C:\react-native\First\node_modules\react-native\Libraries\BatchedBridge\MessageQu…:349)
at C:\react-native\First\node_modules\react-native\Libraries\BatchedBridge\MessageQu…:106
at MessageQueue.__guard (C:\react-native\First\node_modules\react-native\Libraries\BatchedBridge\MessageQu…:297)
I hope someone can help me or give me reference about this problem.
UPDATE: Work on real device.