android-emulator - java.net.ConnectException :/127. 0.0.1:8080 一个安卓模拟器

标签 android-emulator

字符串 url = "http://127.0.0.1:8080/SampleServlet/TestServlet ?";
URL url = 新 URL(con_url);

在安卓模拟器中运行。但我得到了连接异常
02-20 13:05:08.745: 错误/服务器连接 (230): java.net.ConnectException:/127.0.0.1:8080 - 连接被拒绝

请回复我

谢谢

最佳答案

127.0.0.1 是安卓模拟设备自带的环回接口(interface)。

换句话说,您使用 127.0.0.1 连接到 android 模拟设备(而不是您的计算机)。

要通过网络服务器连接到您的机器,请使用 10.0.2.2 或真机 IP 地址(如果您可以从 Web 直接访问)。

使用命令 ipconfig (Windows)/ ifconfig (Linux) 获取您的 IP 地址。

另见 official docsthis !

关于android-emulator - java.net.ConnectException :/127. 0.0.1:8080 一个安卓模拟器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2301560/

相关文章:

android - 调用带 * 字符的电话号码

Android 模拟器给出错误 "Resetting for cold boot: emulation engine failed"并退出

flutter - 如何在没有android studio模拟器的情况下在VSCode中运行flutter应用程序

android - 如何将 PC 网络摄像头用作模拟器的摄像头

android - 有没有办法在 AVD 模拟器上模拟 Android 操作系统升级场景?

android - 安装错误: INSTALL_FAILED_MEDIA_UNAVAILABLE?

android - 当我模拟 Ionic App 时它抛出 TypeError : Can't call method on undefined

android - textCapSentences 适用于模拟器,但不适用于真实设备

xamarin - Visual Studio : Xamarin - Error starting Android Emulator

android - 如何从工具窗口android studio中删除模拟器