Sending gzipped data in WebRequest?

后端 未结 5 616
暖寄归人
暖寄归人 2020-12-09 17:17

I have a large amount of data (~100k) that my C# app is sending to my Apache server with mod_gzip installed. I\'m attempting to gzip the data first using System.IO.Compressi

5条回答
  •  难免孤独
    2020-12-09 17:55

    According to http://www.dominoexperts.com/articles/GZip-servlet-to-gzip-your-pages

    You should setContentType() to the original format, as you are doing with the application/x-www-form-urlencoded I assume. Then...

     // See if browser can handle gzip
     String encoding=req.getHeader("Accept-Encoding");
     if (encoding != null && encoding.indexOf("gzip") >=0 ) {  // gzip browser 
          res.setHeader("Content-Encoding","gzip");
          OutputStream o=res.getOutputStream();
          GZIPOutputStream gz=new GZIPOutputStream(o);
          gz.write(content.getBytes());
          gz.close();
          o.close();
                } else {  // Some old browser -> give them plain text.                        PrintWriter o = res.getWriter();
                        o.println(content);
                        o.flush();
                        o.close();
                }
    

提交回复
热议问题