【发布时间】:2021-05-17 09:29:21
【问题描述】:
我正在开发一个在 Android 模拟器上运行的 Android 应用程序,它应该使用 Axios 从在我的 localhost:3333 上运行的 API 获取数据,问题是当它发送 GET 请求时,我得到了一个网络错误,好像它无法通过使用 baseURL "http://localhost:3333" 访问任何东西。
我知道因为它是一个虚拟机,我应该使用 adb reverse tcp:3333 tcp:3333 将它的端口连接到主机以继续使用“localhost”;
我已经尝试使用没有 adb 反向的 Android Studio IP“http://10.0.2.2:3333”;
我已经尝试使用本地 ip 作为 baseURL;
但问题还在继续……
我没有发布 sn-ps,而是分享项目,因为它们非常简单: 应用程序 https://github.com/March0514s/react-native react-native run-android
API https://github.com/March0514s/backend 纱线开发
Obs.: 我不确定是否有必要重现错误,但在服务器运行后发送以下 POST: curl -X POST -H "Content-Type: application/json" -d '{" title": "project", "name": "你的名字"} http://localhost:3333/projects
提前致谢
【问题讨论】:
标签: android react-native android-studio networking axios