5

Android Client 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 response from server like 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 the Image(binary) from the response.

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

(InputStream)is contains boundary and content information also.

--simple_boundary

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

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

--simple_boundary

How can I get pure Image binary data. And it's possible??

4

3 回答 3

1
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) response.getEntity().getContent());
于 2012-09-26T11:45:02.243 回答
0

您需要一个 http 解析器来读取消息正文。

http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/impl/io/HttpResponseParser.html

于 2012-09-26T14:15:53.353 回答
0

请求内容被拆分和编码,因此处理起来并不容易。

几年前我使用Apache Commons FileUpload来处理这种请求(ei multipart),这个库大大简化了这个过程。

入门部分,您可以找到几个示例。

于 2012-09-26T12:34:32.207 回答