Android中的GZIP

Mik*_*key 3 java android

我只是想问一下在Android中使用HttpClient发送gzip的帖子请求?

在哪里获取要在GZIPOutputstream中传递的OutputStream?

任何片段?

San*_*esh 6

您好UseHttpUriRequest如下所示

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

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

InputStream is = response.getEntity().getContent();
Header contentEncoding = response.getFirstHeader("Content-Encoding");
if (contentEncoding != null && contentEncoding.getValue().equalsIgnoreCase("gzip")) {
    is = new GZIPInputStream(is);
}
Run Code Online (Sandbox Code Playgroud)

  • 该人询问有关发送gzip请求的信息。上面告诉服务器您可以接受gzip的响应并在收到响应时对其进行处理,但是不会对发送的内容进行gzip。 (2认同)