我的Ionic应用程序无法从Android模拟器访问我的本地Node服务器 [英] My Ionic app can't access my local Node server from Android emulator
问题描述
我正在尝试使用电容器在Android模拟器上首次运行我的React/Ionic应用程序.该应用程序应使用Axios连接到我的本地节点服务器.
I'm trying to run for the first time my React/Ionic app on an Android Emulator using Capacitor. The app should connect to my local Node server using Axios.
我的应用在模拟器上成功启动时,所有服务器请求均失败,并显示 Msg:Error:Network Error
While my app started successfully on the emulator, all server requests failed with Msg: Error: Network Error
这是我执行的步骤:
-
我将Axios配置为连接到
http://10.0.2.2:3001
而不是localhost
,但是请求仍然失败
I configured Axios to connect to
http://10.0.2.2:3001
instead oflocalhost
, but the requests still fail
我在Android Emulator Chrome浏览器中打开了网址 http://10.0.2.2:3001/api
,并且在连接到我的服务器时成功并返回响应
I opened the url http://10.0.2.2:3001/api
in the Android Emulator Chrome browser, and it succeeded in connecting to my server and returning a response
我尝试将以下conf添加到我的capacitor.config.json文件中,但是我的应用仍然失败
I tried adding to my capacitor.config.json file the following conf, but my app still fails
"server": {
"allowNavigation": ["10.0.2.2"]
}
您还有其他建议,我应该尝试使我的应用程序连接到本地服务器吗?谢谢
Would you have other advices I should try to make my app connect to my local server? Thank you
推荐答案
搜索后,我在另一个 为允许 To allow 参考: https://developer.android.com/guide/topics/manifest/application-element#usesCleartextTraffic 这篇关于我的Ionic应用程序无法从Android模拟器访问我的本地Node服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! http
而不是 https
请求(Android默认从API级别28开始)这一事实.
http
instead of https
requests which Android forbids by default, starting with API level 28. http
请求,我在我的应用程序的 AndroidManifest.xml
http
requests, I added android:usesCleartextTraffic="true"
to my app's AndroidManifest.xml