2012-11-28 72 views
0

我知道我的PHP文件的作品,我可以從本地調用它,我得到的迴應。 我也知道我有正確的IP地址從AVD調用它,因爲當我從AVD中的瀏覽器調用URL時,我得到一個響應。 所以問題出在我的asynctask函數中。無法連接到WAMP服務器從Android應用

這裏是我的asynctask類的代碼。

protected String doInBackground(String... args) { 
    HttpClient httpclient = new DefaultHttpClient(); 
    HttpResponse response; 
    try { 
     response = httpclient.execute(new HttpGet(url)); 
    } catch (ClientProtocolException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } catch (IOException e) { 
     // TODO Auto-generated catch block 
     e.printStackTrace(); 
    } 

    return null; 
} 

protected void onPostExecute(String str) { 
    // updating UI from Background Thread 
    resp=str; 
    returned(); 
} 

我打電話從父類這個類,並把字符串從onpostexecute()字符串RESP,這是在父類的字符串。響應始終爲空。

+0

你的方法doinbackground返回null。相反,你應該檢查這些問題:你的wamp服務器是否在線?右鍵點擊(放在線)?如果是,android的localhost地址是10.0.2.2,不是localhot或127.0.0.1 – Houcine

回答

2

那麼,您將返回null,所以您的代碼是按照書面形式工作的。

也許代替return nulldoInBackground(),你想返回一部分的http響應?

相關問題