[英]JSOUP and Android Emulator - unable to resolve host
I have virtual host on my Windows 8 - http://test.localhost to my localhost on wamp and test site. 我在Windows 8上有虚拟主机-http://test.localhost到wamp和测试站点上的localhost。 If i use this address in browsers then all working well.
如果我在浏览器中使用此地址,则一切正常。
If i use this in jsoup and my android apps: 如果我在jsoup和我的android应用程序中使用此功能:
Document doc = Jsoup.connect("http://test.localhost").post();
Then I have warning: 然后我有警告:
java.net.UnknownHostException: Unable to resolve host "test.localhost": No address associated with hostname
How can I connect by jsoup with my localhost and Android emulator? 如何通过jsoup与本地主机和Android仿真器连接?
EDIT: 编辑:
URLs from Internet, for example stackoverflow.com etc working fine. 来自Internet的URL,例如stackoverflow.com等可以正常工作。 I would like connect emulator with my localhost.
我想用我的本地主机连接模拟器。
Your Android emulator is a Virtual Machine which has a network stack that is separate from your Windows machine. 您的Android模拟器是一个虚拟机,其网络堆栈与Windows机器是分开的。 If Android did have DNS set to resolve
test.localhost
, it would resolve to itself, not to your Windows host. 如果Android确实设置了DNS来解析
test.localhost
,它将解析为自身,而不是Windows主机。
You need to use your Windows local IP in the URL. 您需要在URL中使用Windows本地IP。 Something like:
就像是:
Document doc = Jsoup.connect("http://192.168.0.1").post();
You can get your local IP with cmd -> ipconfig
您可以使用
cmd -> ipconfig
获取本地IP
You can check that the Android emulator VM can connect through the network to your host with adb shell ping <ip>
您可以使用
adb shell ping <ip>
检查Android模拟器VM是否可以通过网络连接到主机。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.