zoukankan      html  css  js  c++  java
  • HTTP 请求压缩的服务器内容

    从HTTP的角度

    1.  客户端 在http Request  Header上带上 Accept-Encoding:gzip,deflate

    2.  服务器若是支持gzip压缩则在http reponse header部分返回Content-Encoding: gzip 或者Content-Type: application/x-gzip

    3.  body部分用gzip解压缩 则得到网页内容.

    gzip是一种数据格式 默认且目前仅使用deflate算法压缩data部分

    zlib也是一种数据格式,使用defalte算法压缩数据部分.

    deflate是一种压缩算法,是huffman编码的一种加强

      

     
    Accept-Enoding: gzip,deflate              表示浏览器支持gzip

    Content-Encoding: gzip                     表示所请求的页面是通过gzip压缩传输的,服务器开启了gzip是一码事,在程序中使没使用是另外一回事。

     

    connection = getHttpConnection(urlString);
    connection.addRequestProperty("Accept-Encoding", "gzip,deflate");
    bufReader = new BufferedReader(new InputStreamReader( new GZIPInputStream(connection.getInputStream()), "GBK"));
    totalBytes = connection.getContentLength();
    String tmpLine = null;
    while ((tmpLine = bufReader.readLine()) != null) {
    bufStr.append(tmpLine);
    }

     

    即使服务器开启了gzip,如果在请求的头里面不加 ("Accept-Encoding", "gzip,deflate"),获取的流还是不压缩的。


     

     

  • 相关阅读:
    php 基础------数组过滤
    js或者jq 使用cookie 时在谷歌浏览器不好使
    css3 -阻止元素成为鼠标事件目标 pointer-events
    CSS3-----transform 转换
    css3---过渡
    css3动画----animation
    移动端尺寸适配--媒体查询
    工作一年总结
    关于Jquery.Data()和HTML标签的data-*属性
    android shape
  • 原文地址:https://www.cnblogs.com/zijianlu/p/2279670.html
Copyright © 2011-2022 走看看