我正在C#中工作,並且正在爲互聯網下載一個帶有一個XML文件的zip文件。我希望加載這個XML文件。這是我到目前爲止有:在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;
}
在document.Load
我總是收到以下異常:
神奇的數字在gzip頭信息是不正確的。確保你傳入一個GZip流。
我在做什麼錯了?
你下載一個'GZip'或'Zip'?兩者不一樣。 – Oded
'zip!= gzip' - 見http://en.wikipedia.org/wiki/Gzip和http://en.wikipedia.org/wiki/ZIP_%28file_format%29 – Polynomial
我想這是我的第一個錯誤。這是一個不是Gzip的zip文件。 –