API [未处理的承诺被拒绝:TypeError:网络请求失败]

时间:2020-08-20 22:48:15

标签: javascript api

我试图将(Laravel API)与(React本机应用程序)连接,我在邮递员中测试该API,并且可以100%正常运行,但是当我在react本机应用程序中获取时,出现以下错误! >

错误

    [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

,并在应用中显示如下: enter image description here

有我的app.js代码(仅fetch函数):

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);
});
}

2 个答案:

答案 0 :(得分:0)

检查URL再次有两个http。 还要检查您正在调用的API是否已部署在127.0.0.1(您的本地计算机)上

答案 1 :(得分:0)

遇到相同的错误。我没有身体的要求似乎可行。