GZIP output stream
I am trying to GZIP some XML that gets streamed over HTTP (not a web service)
if (ZipOutpu开发者_运维技巧t)
{
output = new GZipStream(Context.Response.OutputStream, CompressionMode.Compress);
Context.Response.AppendHeader("Content-Encoding", "gzip");
}
else
{
output = Context.Response.OutputStream;
}
EscapeXMLTextWriter xmlWriter = new EscapeXMLTextWriter(output, new UTF8Encoding())
{
Formatting = Formatting.Indented
};
ZipOutput
is true
, but the response doesn't seem to be zipped. Any pointers, alternative techniques?
I know I could use SharpZipLib
, but wanted to use the GZipStream
class in the framework.
It looks to me like your code should work - maybe step through it with a debugger to check that the code is really being called as you think it is.
There's a good article on this (including one alternative technique) at - http://www.west-wind.com/weblog/posts/2007/Feb/05/More-on-GZip-compression-with-ASPNET-Content
I figured this issue out I think - it turned out the office firewall was stripping the Accept-Encoding header on outbound requests.
精彩评论