【问题标题】:Connecting to a web server via HttpClient通过 HttpClient 连接到 Web 服务器
【发布时间】:2012-03-01 12:12:24
【问题描述】:

我正在尝试连接到 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 的调试窗口位于链接中:

【问题讨论】:

    标签: android rest httpclient


    【解决方案1】:

    您收到权限拒绝错误。请在应用标签后的清单文件中添加以下权限

     <uses-permission android:name="android.permission.INTERNET"/>
    

    【讨论】:

    • 我添加了这条线并且工作得很好!!它有其他错误,但连接现在正常。非常感谢...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    • 1970-01-01
    • 2016-05-24
    • 2012-02-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多