无法连接到本地主机表单的android模拟器

wfb*_*ale 2 django android localhost httprequest

所以我在我的本地机器上运行了一个django服务器,我想通过我在模拟器中运行的Android应用程序连接到该服务器.当我在Web浏览器中键入它时,一切正常(我得到了我期待的json对象).但是我的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;
Run Code Online (Sandbox Code Playgroud)

我已经尝试过subing for for for localhost127.0.0.1for 10.0.2.2have我尝试过8000端口而不是8080,有人能看到问题吗?

这是堆栈跟踪:(如果在新选项卡中打开它,可以阅读它)

在此输入图像描述

van*_*ram 9

<uses-permission android:name="android.permission.INTERNET" />
Run Code Online (Sandbox Code Playgroud)

在你的android-manifest中