Beispiel #1
0
 private void Write(string content)
 {
     try
     {
         if (content == null)
         {
             content = "";
         }
         byte[] buffer = Encoding.UTF8.GetBytes(content);
         byte[] sdata  = null;
         if (compress.CompressType.ToLower().Equals("deflate"))
         {
             sdata = compress.DeflateCompress(buffer);
             Response.AddHeader("Content-Encoding", "deflate");
         }
         else if (compress.CompressType.ToLower().Equals("gzip"))
         {
             Response.AddHeader("Content-Encoding", "gzip");
             sdata = compress.GZipCompress(buffer);
         }
         else
         {
             sdata = buffer;
         }
         Response.ContentEncoding = Encoding.UTF8;
         WriteByte(sdata);
     }
     catch (Exception e)
     {
         Log.Print(e.Message);
     }
 }
Beispiel #2
0
 private static void WriteByte(HttpListenerContext context_, byte[] buffer)
 {
     byte[] sdata = null;
     if (compress.CompressType.ToLower().Equals("deflate"))
     {
         context_.Response.AddHeader("Content-Encoding", "deflate");
         sdata = compress.DeflateCompress(buffer);
     }
     else if (compress.CompressType.ToLower().Equals("gzip"))
     {
         context_.Response.AddHeader("Content-Encoding", "gzip");
         sdata = compress.GZipCompress(buffer);
     }
     else
     {
         sdata = buffer;
     }
     context_.Response.ContentLength64 = sdata.Length;
     context_.Response.OutputStream.Write(sdata, 0, sdata.Length);
     context_.Response.OutputStream.Close();
     context_.Response.Close();
 }