小编ALb*_*wad的帖子

API [未处理的承诺拒绝:类型错误:网络请求失败]

我正在尝试将(Laravel API)与(React 本机应用程序)连接,我在邮递员中测试了 API,它 100% 正常工作,但是当我在本机应用程序中获取时,出现以下错误!

错误

    [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
Run Code Online (Sandbox Code Playgroud)

在应用程序中,它显示如下: 在此处输入图片说明

有我的 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);
});
}
Run Code Online (Sandbox Code Playgroud)

javascript api

5
推荐指数
1
解决办法
2031
查看次数

标签 统计

api ×1

javascript ×1