Android使用restlet与GAE进行通信的挑战

时间:2012-05-16 18:59:46

标签: android google-app-engine gwt restlet

我正在使用Eclipse(尝试)构建Android客户端以重用我使用GAE和GWT开发的restlet服务。

我的服务正在

运行
    http://127.0.0.1:8888/abc/audits  

我可以通过直接访问此URL并使用我的GWT客户端来测试这一点 - 两者都有效。

但是,以下代码返回通信错误

    private AuditsResource resource;
    private Audits audits;

    ClientResource cr = new ClientResource("http://127.0.0.1:8888/abc/audits");
    resource = cr.wrap(AuditsResource.class);
    try {
    // Get the remote contact
     audits = resource.retrieve();
    // The task is over, let the parent conclude.
    handler.sendEmptyMessage(0);
    } catch (Exception e) {
        Message msg = Message.obtain(handler, 2);
        Bundle data = new Bundle();
        data.putString("msg", "Cannot get the contact due to: "
            + e.getMessage());
        msg.setData(data);
        handler.sendMessage(msg);
    }

我不知道接下来要去哪儿。我已经检测了AuditsResource的服务器实现,并且从未触及过(通过Android应用程序)。

AuditsResource类有一个方法,暂时保持简单

    @Get
    public Audits retrieve();

2 个答案:

答案 0 :(得分:0)

问题是Andriod仿真器无法连接到127.0.0.1或10.0.2.2。解决方案是使用您PC的IP地址。

答案 1 :(得分:0)

我可以使用10.0.2.2代替localhost,通过Android / Restlet从Android连接到我的本地Google App Engine。

相关问题