Pracuję w języku C#, a ja pobieram do Internetu plik zip z jednym plikiem XML. i chcę załadować ten plik XML. To, co mam tak daleko:Rozpakowywanie strumienia w języku C#
byte[] data;
WebClient webClient = new WebClient();
try {
data = webClient.DownloadData(downloadUrl);
}
catch (Exception ex) {
Console.WriteLine("Error in DownloadData (Ex:{0})", ex.Message);
throw;
}
if (data == null) {
Console.WriteLine("Bulk data is null");
throw new Exception("Bulk data is null");
}
//Create the stream
MemoryStream stream = new MemoryStream(data);
XmlDocument document = new XmlDocument();
//Gzip
GZipStream gzipStream = new GZipStream(stream, CompressionMode.Decompress);
//Load report straight from the gzip stream
try {
document.Load(gzipStream);
}
catch (Exception ex) {
Console.WriteLine("Error in Load (Ex:{0})", ex.Message);
throw;
}
w document.Load
Ja zawsze otrzymuję następujący wyjątek:
liczba magiczna w nagłówku GZIP nie jest poprawna. Upewnij się, że przekazujesz strumień GZip.
Co robię źle?
Czy pobierając 'GZip' lub' Zip'? Te dwie nie są takie same. – Oded
'zip! = Gzip' - Zobacz http://en.wikipedia.org/wiki/Gzip i http://pl.wikipedia.org/wiki/ZIP_%28file_format%29 – Polynomial
Myślę, że to mój pierwszy błąd. Jest to plik zip, a nie Gzip. –