简体   繁体   English

无法从 Android Emulator 访问 localhost,但在 Simulator 上它正在工作

[英]Can't access localhost from Android Emulator, but on Simulator it's working

Hope anyone can help.希望任何人都可以提供帮助。

Why I can't access localhost (10.0.2.2) from Android Emulator, but when accessing from Simulator it's working.为什么我无法从 Android Emulator 访问 localhost (10.0.2.2),但是从 Simulator 访问时它正在工作。

I was try to edit server configuration as noticed from many tutorials, but still not working.我试图编辑许多教程中注意到的服务器配置,但仍然无法正常工作。

Here the screenshots.这里是截图。

Use a port number along with IP使用端口号和 IP

http:// 10.0.2.2:8080 http://10.0.2.2:8080

Works perfect !工作完美!

or或者

you can use IP of your pc which you can get by typing ifconfig in terminal.你可以使用你的电脑的 IP,你可以通过在终端中输入ifconfig来获得。 Something like就像是

http://192.168.1.2 http://192.168.1.2

I have found the solution for my problem.我已经找到了解决我的问题的方法。

I try to change the port, so it working fine.我尝试更改端口,所以它工作正常。

adb reverse tcp:8000 tcp:8000

And now I can access my computer localhost on Android with accessing localhost:8000.现在我可以通过访问 localhost:8000 在 Android 上访问我的计算机本地主机。

I just got the same problem and the reason of why I could not connect to my machine was the setting of the emulator.我刚刚遇到了同样的问题,无法连接到我的机器的原因是模拟器的设置。

How to solve:怎么解决:

  1. Open emulator.打开模拟器。
  2. Find the button with 3 dots, press it.找到带有3个点的按钮,按下它。
  3. Go to "Settings" menu.转到“设置”菜单。
  4. Disable "Use Android studio HTTP proxy settings".禁用“使用 Android Studio HTTP 代理设置”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法从 android 模拟器连接到 localhost - Can't connect to localhost from android emulator 无法从Android Windows模拟器(Visual Studio 2015 / Xamarin)访问localhost - Can't access localhost from Android Windows Emulator (Visual Studio 2015 / Xamarin) 从 Android 模拟器访问 laravel valet 上的本地主机 - Access localhost on laravel valet from Android emulator 如何从 Genymotion android 模拟器访问本地主机? - How to access localhost from a Genymotion android emulator? 无法通过 Android 应用访问我的笔记本电脑的本地主机 - Can't access my laptop's localhost through an Android app 我的Android应用无法访问计算机的本地主机 - My android app can't access my computer's localhost Android 模拟器浏览器无法访问主机文件上设置的本地主机子域 - Android emulator browser can't access to localhost subdomains set on hosts file 无法从我的Android模拟器访问HTTPS - Can't access HTTPS from my Android Emulator 为什么Android模拟器无法从在线服务器访问API? - Why Android emulator can't access API from online server? 如何从NOX应用程序播放器android模拟器访问localhost? - How to access localhost from a NOX app player android emulator?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM