无法从仿真器联系主机(10.0.2.2)

Til*_*aat 5 android http

我的笔记本电脑上运行了一个python REST API服务器.我正在尝试使用Apache的客户端(org.apache.http.client)库在Android中编写一个rest客户端(使用Eclipse ADT等)来联系它.

代码非常简单,基本上可以做到以下几点 -

HttpGet httpget = new HttpGet(new URI("http://10.0.2.2:8000/user?username=tim"));
HttpResponse response = httpclient.execute(httpget);
Run Code Online (Sandbox Code Playgroud)

但是在执行时,它会因超时异常而异常.我甚至无法通过模拟器中的浏览器来访问URL.

例外的细节

org.apache.http.conn.ConnectTimeoutException: Connect to /10.0.2.2:8000 timed out
Run Code Online (Sandbox Code Playgroud)

但是,我尝试在笔记本电脑上使用Chrome上的cREST客户端,我可以很好地查询REST服务器.

Mik*_*lov -1

该机器是否可能不在您的网络上?即 - 它位于路由器的另一侧,在互联网上的某个地方?因为地址以“10”开头。被保留为私有地址且不可路由。

请参阅http://en.wikipedia.org/wiki/Private_network了解更多信息