java – 可以使用GZIP压缩HTTP请求吗?

栏目: Java · 发布时间: 7年前

内容简介:我正在使用我的移动设备上的Java ME应用程序与Tomcat服务器进行通信.代码日志版权声明:翻译自:http://stackoverflow.com/questions/1450151/can-i-compress-http-requests-using-gzip

我正在使用我的移动设备上的Java ME应用程序与Tomcat服务器进行通信.

现代手机拥有如此多的CPU功率,网络相对较慢,因此压缩是非常有意义的.这也很容易做到.

在J2ME端,你做这样的事情(假设你使用HttpConnection),

hc.setRequestProperty("Accept-Encoding", "gzip, deflate");
  if (hc.getResponseCode() == HttpConnection.HTTP_OK) {
      InputStream in = hc.openInputStream();
      if ("gzip".equals(hc.getEncoding())) 
         in = new GZIPInputStream(in);
  ...

我们使用来自氯仿的GZIPInputStream,但我确信还有其他的,

http://www.tinyline.com/utils/index.html

在服务器端,它都是内置的.只需在Tomcat的server.xml中的Connector中添加以下属性,

<Connector 
compression="on"
compressionMinSize="2048"
compressableMimeType="text/html,application/json"
... />

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/1450151/can-i-compress-http-requests-using-gzip


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Cracking the Coding Interview

Cracking the Coding Interview

Gayle Laakmann McDowell / CareerCup / 2015-7-1 / USD 39.95

Cracking the Coding Interview, 6th Edition is here to help you through this process, teaching you what you need to know and enabling you to perform at your very best. I've coached and interviewed hund......一起来看看 《Cracking the Coding Interview》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具