2012-03-01 200 views
0

我試圖連接到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

回答

1

你得到許可拒絕錯誤。請在應用程序標籤後在清單文件中添加以下權限

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

我添加了該行並且工作得很好!它有其他錯誤,但連接正在工作。非常感謝... – trebew 2012-03-01 12:37:06