通过HttpClient连接到Web服务器

时间:2012-03-01 12:12:24

标签: android rest httpclient

我正在尝试连接到REST Web服务器,但我不知道出了什么问题。连接的代码是:

public List<Agenda> getAgenda(String dia) {
    try {
        Log.i(TAG, "It is inside getAgenda()");
        HttpClient client = new DefaultHttpClient();
        HttpGet method = new HttpGet(Settings.getServiceUrl() + "/" + dia);
        Log.i(TAG, Settings.getServiceUrl() + "/" + dia);
        //the line above prints: http://192.168.0.100/odonto/agenda.php/2012-02-01
        HttpResponse resp = client.execute(method);
        //return loadFromJSONArray(client.execute(method));
        Log.i(TAG, "Recebeu a response");
        return loadFromJSONArray(resp);
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

嗯,这就是事情:行

Log.i(TAG, Settings.getServiceUrl() + "/" + dia);

正确地在调试窗口上打印。但是这句话:

Log.i(TAG, "Recebeu a response");

不打印。所以问题在于:

HttpResponse resp = client.execute(method);

但我真的不知道怎么会出错!我已经用Firefox测试了REST服务器,它运行得很好!带有过滤器的调试窗口只显示标签System.err在链接中:

enter image description here

1 个答案:

答案 0 :(得分:1)

您正在获得权限拒绝错误。请在申请标记

之后在清单文件中添加以下权限
 <uses-permission android:name="android.permission.INTERNET"/>
相关问题