2013-03-22 76 views
0

我正在寫一個簡單的Android應用程序,它在特定位置解析html,獲取一些數據並顯示在ListView中。由於應用程序只需要簡單的html響應,有沒有可能只請求純html。如何從http請求中排除css和java腳本文件,圖像和類似內容? 我正在使用apache HttpClient對象。如何強制HttpClient獲取純html?

+0

任何人知道? ping – 2013-03-23 05:02:25

回答

1

這是回答您的問題嗎?如果是的話,記得在一個單獨的線程中執行是爲了避免阻塞UI(可能要使用AsyncTask

(從How to get the html-source of a page from a html link in android?

HttpClient client = new DefaultHttpClient(); 
HttpGet request = new HttpGet(url); 
HttpResponse response = client.execute(request); 

String html = ""; 
InputStream in = response.getEntity().getContent(); 
BufferedReader reader = new BufferedReader(new InputStreamReader(in)); 
StringBuilder str = new StringBuilder(); 
String line = null; 
while((line = reader.readLine()) != null) 
{ 
    str.append(line); 
} 
in.close(); 
html = str.toString(); 
+0

感謝您的回答。我已經實現了(類似的代碼)。 但我想知道是否只需要簡單的html響應或一切(圖像,CSS文件,Java腳本文件和類似的)該特定的http請求。如果是的話,我怎樣才能明確禁用除了普通的HTML響應之外的所有內容...... – 2013-03-22 05:54:43