'API [Unhandled promise rejection: TypeError: Network request failed]

I am trying to connect (Laravel API) with (React native app), I test the API in the postman and it working 100% fine, but when I fetch in the react native app I got the following error !

the error

    [Unhandled promise rejection: TypeError: Network request failed]
- node_modules\whatwg-fetch\dist\fetch.umd.js:527:17 in setTimeout$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:387:16 in callTimers
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425:19 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue

and in the app, it shows like this: enter image description here

there is my app.js code(only the fetch function ):

myfun = async()=>{

await fetch('http://127.0.0.1:8000/api/login',{

    method:'POST',
    headers:{
        'Accept': 'application/json',
        'Content-Type': 'application/json'
    },
    body: JSON.stringify({"email":email, "password": passowrd})
}).then(res => res.json())
.then(resData =>{
    alert(resData);
    console.log(resData);
});
}


Solution 1:[1]

This may be a bit late but to help others: In your fetch, you must add your IPv4 address (usually starts with 192)

then replace

await fetch('http://127.0.0.1:8000/api/login'

with

await fetch('http://192.xxx.x.xx:8000/api/login'

And in laravel, starts your port with the same host (in your terminal):

php artisan serve --host 192.xxx.x.xx --port="8000"

It worked for me :)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Camille D