2014-02-17 133 views
0

我試圖從我的辦公室服務器獲得響應。響應至少有50,000行。但我沒有得到完整的迴應。我不知道哪裏出了問題。是否完整的數據沒有得到下載或任何其他問題與我的InputStream?在Android中不完整的http響應

HttpClient httpClient = new DefaultHttpClient(); 
HttpContext httpcontext = new BasicHttpContext(); 
HttpPost httpPost = new HttpPost(mUrl); 
HttpResponse mResponse = httpClient.execute(httpPost, httpcontext); 
InputStream mResponseStream = mResponse.getEntity().getContent(); 
BufferedReader br = new BufferedReader(new InputStreamReader(mResponseStream)); 
String line = ""; 
while ((line = br.readLine()) != null) { 
    line = line.replaceAll("[\r\n]", ""); 
    Log.v("Response", line); 
} 

所需的響應:

02-17 18:32:14.000: D/Lib(4121): Starts 
02-17 18:32:14.010: D/Lib(4121): 12080964|~|1370.00 
02-17 18:32:14.010: D/Lib(4121): 12083142|~|500.00 
02-17 18:32:14.020: D/Lib(4121): 13051372|~|100.00 
02-17 18:32:14.020: D/Lib(4121): 13040457|~|12.00 
02-17 18:32:14.060: D/Lib(4121): 12010037|~|170.00 
02-17 18:32:14.060: D/Lib(4121): ......... 
02-17 18:32:14.060: D/Lib(4121): Ends 

獲得響應:

02-17 18:32:14.000: D/Lib(4121): Starts 
02-17 18:32:14.010: D/Lib(4121): 12080964|~|1370.00 
02-17 18:32:14.010: D/Lib(4121): 12083142|~|500.00 
02-17 18:32:14.020: D/Lib(4121): 13051372|~|100.00 
02-17 18:32:14.020: D/Lib(4121): 13040457|~|12.00 
02-17 18:32:14.060: D/Lib(4121): 12010037|~|170.00 
02-17 18:32:14.060: D/Lib(4121): ......... 

我的回答總是Starts關鍵字開始,以Ends關鍵字結束。總是我沒有得到Ends關鍵字。行號在25,000到33,000行之間停止響應。謝謝。

+0

,你會得到什麼,當你用手或通過像捲曲的工具要求呢? (順便說一句:你應該做GET請求,而不是POST - 你發送任何東西都不需要POST) –

+0

試圖給大小BufferedReader – Sonali8890

+0

@MarcinOrlowski我發送數據進行身份驗證,我沒有使用捲曲。 – SathishKumar

回答

0

這裏我從響應中得到字符串後,我將該字符串響應轉換爲InputStream,這個過程給出了完整的響應。雖然我試圖從響應中獲得InputStream,但它返回的是不完整的數據。無論如何,我得到了完整的答覆,但直到我不知道爲什麼我不能使用mResponse.getEntity().getContent()得到完整的答覆。

我的工作代碼,

HttpClient httpClient = new DefaultHttpClient(); 
HttpContext httpcontext = new BasicHttpContext(); 
HttpPost httpPost = new HttpPost(mUrl); 
HttpResponse mResponse = httpClient.execute(httpPost, httpcontext); 
String responseString=EntityUtils.toString(mResponse.getEntity()); 
InputStream mResponseStream = new ByteArrayInputStream(responseString.getBytes(HTTP.UTF_8)); 
BufferedReader br = new BufferedReader(new InputStreamReader(mResponseStream)); 
String line = ""; 
while ((line = br.readLine()) != null) { 
    line = line.replaceAll("[\r\n]", ""); 
    Log.v("Response", line); 
}