Sto tentando di inviare dati al server che accetta dati compressi. Il codice qui sotto funziona bene, ma non è compresso. Non ho lavorato con la compressione o con Gzip, quindi qualsiasi aiuto è utile.Come comprimere un POST 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());
}
Do gzip l'intero array di byte? Devo aggiungere altre intestazioni o rimuovere quello che è già lì?
Grazie!
-Scott
L'articolo collegato spiega come decomprimere dati restituiti in una risposta, ma non come strutturare la richiesta utilizzando dati compressi. – Scott
@Scott aggiornato. –