React Native:即使可以从仿真器浏览器访问,也无法连接到localhost

问题描述 投票:0回答:1

我正在使用android应用,遇到一个奇怪的问题,当我调用我的API时出现此错误:

enter image description here

enter image description here

在模拟器中,当我打开浏览器并键入在env文件中配置的相同URL时,得到响应!

但是在应用程序中,它不起作用,我在API终端上看不到任何东西。

我尝试过的是:

1)adb反向tcp:3000 tcp:300 =>没有结果

2)使用10.0.2.2 =>没有结果

3)我也将端口从8081更改为1234,并将其添加到(ctrl+m >> settings>>Debug server and host),关闭应用程序并启动它

with react-native run-android --port=1234 
android api react-native android-emulator
1个回答
0
投票

如果您正在调用任何API,则无法调用服务器。这就是问题。也尝试一次检查Internet。

© www.soinside.com 2019 - 2024. All rights reserved.