从HTTP Response Body获取图像文件

Yan*_*Ahn 5 java android multipart httpresponse

Android客户端向服务器发送请求.

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://test.com/test");
HttpResponse response = httpclient.execute(httppost);
Run Code Online (Sandbox Code Playgroud)

然后收到服务器的响应,如下所示

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Date: Wed, 26 Sep 2012 10:59:35 GMT
Content-Type: multipart/form-data; type="image/jpeg"; boundary="simple_boundary"; start="<image>"; start-info="image/jpeg"
Transfer-Encoding: chunked

2000

--simple_boundary

Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <image>

......JPEG Binary Code Here.....

--simple_boundary
Run Code Online (Sandbox Code Playgroud)

如何从响应中获取图像(二进制).

InputStream is = response.getEntity().getContent();
Run Code Online (Sandbox Code Playgroud)

(InputStream)也包含边界和内容信息.

--simple_boundary

Content-Type: image/jpeg
Content-Transfer-Encoding: binary
Content-ID: <image>

......JPEG Binary Code Here.....

--simple_boundary
Run Code Online (Sandbox Code Playgroud)

如何获得纯Image二进制数据.它有可能??

Ric*_*ard 1

Bitmap bitmap = BitmapFactory.decodeStream((InputStream) response.getEntity().getContent());
Run Code Online (Sandbox Code Playgroud)