Get image file from HTTP Response Body

The Android client will send a request to the server.

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

and then received a response from the server as shown below

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

How can I get an image (binary) from an answer.

InputStream is = response.getEntity().getContent();

(InputStream) also contains border and content information.

--simple_boundary

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

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

--simple_boundary

How can I get pure binary image data. And is that possible?

+5
source share
3 answers
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) response.getEntity().getContent());
+1
source

The request content is split and encoded, so it’s easy to handle.

I used Apache Commons FileUpload several years ago to process such a request (ei multipart), this library has greatly simplified the process.

.

0

All Articles