2 qq 21272341 qq_21272341 于 2017.01.03 15:27 提问

android Service网络下载视频

下面这段代码在Service中运行和在Activity中运行得到的长度为什么会不同
HttpClient httpClient=new DefaultHttpClient();
HttpPost httpPost=new HttpPost(HttpUrlUtil.WEBSERVER_PATH+downloadPath);
httpResponse=httpClient.execute(httpPost);
HttpEntity httpEntity=httpResponse.getEntity();
BufferedHttpEntity bufferedHttpEntity = new BufferedHttpEntity(httpEntity);
System.out.println(httpResponse.getStatusLine().toString());
System.out.println("bufferedHttpEntity"+bufferedHttpEntity.getContentLength());

在Service onStartCommand中运行返回的bufferedHttpEntity.getContentLength()一直都是6277,httpResponse.getStatusLine().toString()返回的是200

2个回答

u012758599
u012758599   2017.01.03 16:07

response.getStatusLine().getStatusCode()==200链接成功,你打印的应该是这个吧

Mr_dsw
Mr_dsw   Ds   Rxr 2017.01.04 12:59

httpResponse.getStatusLine().toString()这不是返回长度,而是标识码,200就是连接成功了。

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!