【发布时间】:2022-01-04 21:17:04
【问题描述】:
我正在尝试将 API 与我的 react 本机应用程序集成,但是当我提出请求时,我总是收到网络错误:
[Unhandled promise rejection: TypeError: Network request failed]
at node_modules\whatwg-fetch\dist\fetch.umd.js:541:17 in setTimeout$argument_0
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:123:14 in _callTimer
at node_modules\react-native\Libraries\Core\Timers\JSTimers.js:379:16 in callTimers
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:414:4 in __callFunction
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:113:6 in __guard$argument_0
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:365:10 in __guard
at node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:4 in callFunctionReturnFlushedQueue
at [native code]:null in callFunctionReturnFlushedQueue
我的 axios 配置如下:
import axios from "axios";
const baseUrl = 'http://localhost:8000/'
export const api = axios.create({baseURL: baseUrl});
还尝试了“http://10.0.2.2:8000/”和“http://127.0.0.1:8000”,但得到了同样的错误。
有人可以帮我吗?提前谢谢你!
【问题讨论】:
标签: react-native axios fastapi uvicorn