Currently, I have a web application built using React and an API developed in Laravel. Now, I am planning to create a mobile app that will also utilize the same API. However, I'm encountering an issue where I cannot fetch data due to receiving the error message:
NETWORK REQUEST FAILED.
This is the code snippet I am using to attempt fetching the data:
handleButton = () => {
try {
fetch(`127.0.0.1:8081/test`).then(response =>
console.log(response)
);
} catch (e) {
console.log(e);
}
};
I have attempted solutions like changing the IP address in the dev settings to my machine id or using localhost instead of the IP address 127.0.0.1, but unfortunately, these attempts did not resolve the issue. The error message I keep encountering states:
Possible Unhandled Promise Rejection (id: 0):
TypeError: Network request failed
TypeError: Network request failed
at XMLHttpRequest.xhr.onerror (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:42556:18)
at XMLHttpRequest.dispatchEvent (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:47998:27)
at XMLHttpRequest.setReadyState (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46859:20)
at XMLHttpRequest.__didCompleteResponse (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46686:16)
at blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:46796:47
at RCTDeviceEventEmitter.emit (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16875:37)
at MessageQueue.__callFunction (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16488:44)
at blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16245:17
at MessageQueue.__guard (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16442:13)
at MessageQueue.callFunctionReturnFlushedQueue (blob:http://localhost:8081/cfc373de-8318-4df3-b46a-7b17d4926c5e:16244:14)
EDIT:
To interact with my Android Studio emulator, as I do not currently own an Android device running on Android version above 5.