2014-02-17 93 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); 
}