我有大量数据(约100k)要通过C#应用程序发送到安装了mod_gzip的Apache服务器。我尝试使用System.IO.Compression.GZipStream先对数据进行压缩。PHP接收到原始的gzipped数据,所以Apache没有像我期望的那样解压缩它。我是否漏掉了什么?
System.Net.WebRequest req = WebRequest.Create(this.Url);
req.Method = this.Method; // "post"
req.Timeout = this.Timeout;
req.ContentType = "application/x-www-form-urlencoded";
req.Headers.Add("Content-Encoding: gzip");
System.IO.Stream reqStream = req.GetRequestStream();
GZipStream gz = new GZipStream(reqStream, CompressionMode.Compress);
System.IO.StreamWriter sw = new System.IO.StreamWriter(gz, Encoding.ASCII);
sw.Write( large_amount_of_data );
sw.Close();
gz.Close();
reqStream.Close()
System.Net.WebResponse resp = req.GetResponse();
// (handle response...)
我不完全确定"Content-Encoding: gzip"是否适用于客户端提供的头信息。