我正在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文件。 –