2012-09-26 3 views
4

Android 클라이언트가 서버에 요청을 보냅니다.HTTP 응답 본문에서 이미지 파일 가져 오기

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

다음은 어떻게 응답에서 이미지 (바이너리)를 얻을 수

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 

아래와 같이 서버에서 응답을 받았습니다.

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

(InputStream)에는 경계 및 내용 정보도 들어 있습니다.

--simple_boundary 

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

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

--simple_boundary 

어떻게 순수한 이미지 바이너리 데이터를 얻을 수 있습니까? 그리고 가능합니까 ??

답변

1
Bitmap bitmap = BitmapFactory.decodeStream((InputStream) response.getEntity().getContent()); 
+0

작동하지 않습니다. InputStream에는 바이너리 데이터뿐만 아니라 컨텐츠 정보가 포함되어있다. –

0

요청 내용이 분할되어 인코딩되므로 쉽게 처리 할 수 ​​없습니다.

나는이 종류의 요청 (예 : multipart)을 처리하기 위해 Apache Commons FileUpload 년 전에이 라이브러리를 사용하여 프로세스를 크게 간소화했습니다.

getting started 섹션에는 몇 가지 예가 나와 있습니다.