通过HttpClient连接到Web服务器

通过HttpClient连接到Web服务器

问题描述:

我试图连接到REST Web服务器,我不知道错在哪里。连接的代码是:通过HttpClient连接到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

你得到许可拒绝错误。请在应用程序标签后在清单文件中添加以下权限

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

我添加了该行并且工作得很好!它有其他错误,但连接正在工作。非常感谢... – trebew 2012-03-01 12:37:06