gpt4 book ai didi

java - 从 HTTP 响应主体获取图像文件

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:33 26 4
gpt4 key购买 nike

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

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

如何获得纯图像二进制数据。这可能吗??

最佳答案

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

关于java - 从 HTTP 响应主体获取图像文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12600742/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com