2010-05-08 17 views
2

我在Android 1.5,我的代碼是這樣的:爲什麼我的HttpPost無法接收所有的響應數據?

HttpPost httpPost = new HttpPost(url); 
HttpEntity entity = new UrlEncodedFormEntity(params, HTTP.UTF_8); 
httpPost.setEntity(entity); 

HttpResponse response = httpClient.execute(httpPost); 
HttpEntity respEntity = response.getEntity(); 
String result = EntityUtils.toString(respEntity, DEFAULT_CHARSET); 

後成功地執行這些代碼,結果是一個精簡的字符串。我試過使用瀏覽器來測試url + param,它工作正常,並獲得所有數據。

這段代碼有什麼問題?我需要指定哪些參數?

+0

如何剝離被剝離? 「DEFAULT_CHARSET」與響應主體的實際字符集是否匹配? – BalusC 2010-05-08 02:54:24

+0

是的,DEFAULT_CHARSET匹配實際的字符集。我可以得到像2k內容併成功解碼。但無法獲取所有數據。 – Johnny 2010-05-08 03:19:59

+0

對不起,我發現其實答案有完整的數據。這是因爲android.util.Log具有輸出長度限制。所以我認爲數據不完整。 – Johnny 2010-05-08 13:01:46

回答

0

這工作:

 
HttpResponse response=httpclient.execute(httppost); 
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); 
相關問題