Android中的GZIP

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

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

任何片段?

您好UseHttpUriRequest如下所示

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

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

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

如果您的数据不是太大,您可以这样做:

 HttpClient httpClient = new DefaultHttpClient(); HttpPost httpost = new HttpPost(POST_URL); ByteArrayOutputStream baos = new ByteArrayOutputStream(); GZIPOutputStream gos = new GZIPOutputStream(baos); gos.write(data.getBytes()); gos.close(); ByteArrayEntity byteArrayEntity = new ByteArrayEntity(baos.toByteArray()); httpost.setEntity(byteArrayEntity);