Tôi có một lượng lớn dữ liệu (~ 100k) mà ứng dụng C# của tôi đang gửi tới máy chủ Apache của tôi với cài đặt mod_gzip. Tôi đang cố gắng gzip dữ liệu đầu tiên bằng cách sử dụng System.IO.Compression.GZipStream. PHP nhận dữ liệu gzipped thô, vì vậy Apache không giải nén nó như tôi mong đợi. Tui bỏ lỡ điều gì vậy?Gửi dữ liệu gzipped trong WebRequest?
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...)
Tôi không hoàn toàn chắc chắn "Content-Encoding: gzip" áp dụng cho tiêu đề do khách hàng cung cấp.
+1 cho mã đăng dữ liệu đã nén. Tôi tin rằng bạn là người duy nhất đã làm như vậy trong toàn bộ thời đại Internet ;-) –
Rất thích nghe nếu bất kỳ ý tưởng nào dưới đây đã giúp bạn - Tôi đang cố gắng giải quyết cùng một vấn đề. –