无法连接到本地主机形式android模拟器
问题描述:
所以我有一个django服务器运行在我的本地机器上,我想通过我在仿真器中运行的android应用程序连接到。当我在Web浏览器中输入这些信息时(我得到我期待的json对象),一切正常。但我的android代码不起作用。无法连接到本地主机形式android模拟器
try {
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setURI(new URI("http://10.0.2.2:8080/getUserInfo/" + username + "/"));
//next line throws exception
HttpResponse response = client.execute(request);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("GET RESPONSE",EntityUtils.toString(resEntity));
String jsonString = EntityUtils.toString(resEntity);
return jsonToAccount(jsonString);
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
我试图在localhost
和127.0.0.1
为10.0.2.2
底涂,我也尝试过的,而不是8080 8000端口,任何人可以看到这个问题?
这里是堆栈跟踪:(如果你在新标签中打开它,你可以阅读)
答
把
<uses-permission android:name="android.permission.INTERNET" />
在您的Android清单
+17
我讨厌自己.. – wbarksdale
无。 但是你可以。请发布堆栈跟踪:) – MByD
永远不要在PC上设置服务器,并使用它来测试仿真器中的应用程序,但是:不会将'127.0.0.1'等引用到手机/仿真器中作为本地主机这种情况下,而不是你试图达到的主机? – 2011-11-28 20:40:35
你在网页浏览器中输入什么(完全)? – hovanessyan