using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.IO.Compression; namespace WebApplication2 { /// <summary> /// $codebehindclassname$ 的摘要说明 /// </summary> [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] public class GZipHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string acceptEncoding = context.Request.Headers["Accept-Encoding"].ToString().ToUpperInvariant(); if (acceptEncoding.Length > 0) { if (acceptEncoding.Contains("GZIP")) { context.Response.AppendHeader("Content-encoding", "gzip"); context.Response.Filter = new GZipStream(context.Response.Filter, CompressionMode.Compress); } else if (acceptEncoding.Contains("DEFLATE")) { context.Response.AppendHeader("Content-encoding", "deflate"); context.Response.Filter = new DeflateStream(context.Response.Filter, CompressionMode.Compress); } } context.Response.Write("Hello World"); } public bool IsReusable { get { return false; } } } }