GZIP在Android中GZIP、Android

2023-09-05 04:55:56 作者:说走就走.

我只是想问有关发送GZIP在Android的使用HttpClient的POST请求?

i just wanted to ask about sending gzip for post requests using HttpClient in Android?

从哪里获取的OutputStream将在GZIPOutputstream通过呢?

where to get that OutputStream to be passed in the GZIPOutputstream?

任何片段?

推荐答案

喜UseHttpUriRequest如下图

Hi UseHttpUriRequest as shown below

 String urlval=" http"//www.sampleurl.com/";
    HttpUriRequest req = new HttpGet(urlval);
    req.addHeader("Accept-Encoding", "gzip");
    httpClient.execute(req);

,然后检查响应的内容编码,如下所示:

and then Check response for content encoding as shown below :

InputStream is = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
    is = new GZIPInputStream(is);
}
 
精彩推荐
图片推荐