Tôi đang cố đăng dữ liệu lên máy chủ chấp nhận dữ liệu đã nén. Mã dưới đây hoạt động tốt, nhưng nó không nén. Tôi đã không làm việc với nén hoặc Gzip beofre, vì vậy bất kỳ trợ giúp là appriciated.Cách nén một Bài đăng HttpWebRequest
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
request.Timeout = 600000;
request.Method = verb; // POST
request.Accept = "text/xml";
if (!string.IsNullOrEmpty(data))
{
request.ContentType = "text/xml";
byte[] byteData = UTF8Encoding.UTF8.GetBytes(data);
request.ContentLength = byteData.Length;
// Here is where I need to compress the above byte array using GZipStream
using (Stream postStream = request.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
}
}
XmlDocument xmlDoc = new XmlDocument();
HttpWebResponse response = null;
StreamReader reader = null;
try
{
response = request.GetResponse() as HttpWebResponse;
reader = new StreamReader(response.GetResponseStream());
xmlDoc.LoadXml(reader.ReadToEnd());
}
Tôi có gzip toàn bộ mảng byte không? Tôi có cần phải thêm các tiêu đề khác hoặc xóa tiêu đề đã có ở đó không?
Cảm ơn!
-Scott
Bài viết được liên kết giải thích cách giải nén dữ liệu được trả về, nhưng không phải cách cấu trúc yêu cầu sử dụng dữ liệu nén. – Scott
@Scott Đã cập nhật. –