Brainfreeze 与 gzip 文件,包含我想要作为流的 xml 文件
这个让我很头疼,我需要一个 XML feed,但 feed 位于 gzip 文件内。 现在我可以下载、解压、保存文件等,
但我想做的是将 gzip 获取到内存中 将内容放入内存 将内容读入内存 然后将其传递给序列化器,
这里的问题是结果包含不可读的乱码,而 reader1 和 reader 均不包含任何乱码。我在这里缺少另一行,但似乎无法找到它是什么。
var request = (HttpWebRequest)HttpWebRequest.Create("urltofeed.com");
request.Credentials = CredentialCache.DefaultCredentials;
// auto unpack gzip
request.AutomaticDecompression = DecompressionMethods.GZip;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader data = new StreamReader(response.GetResponseStream());
var result = data.ReadToEnd();
XmlReader reader1 = XmlReader.Create(response.GetResponseStream());
var reader = new XmlTextReader(response.GetResponseStream());
this one is baking my head, i need an XML feed, but the feed is inside a gzip file.
now i can download, unpack, save file etc.
but what i want to do is get the gzip in memory
put the contents into memory
read the contents into memory
and then pass that to the serializer
problem here is that results contain unreadable gibberish and reader1 and reader both contain none. I am missing another line here but cant seem to find what it is.
var request = (HttpWebRequest)HttpWebRequest.Create("urltofeed.com");
request.Credentials = CredentialCache.DefaultCredentials;
// auto unpack gzip
request.AutomaticDecompression = DecompressionMethods.GZip;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader data = new StreamReader(response.GetResponseStream());
var result = data.ReadToEnd();
XmlReader reader1 = XmlReader.Create(response.GetResponseStream());
var reader = new XmlTextReader(response.GetResponseStream());
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
来自 MSDN 的直接信息:
所以在你的情况下喜欢
Direclty from MSDN:
So in your case something like
您必须解压缩 gzip 文件,该步骤缺失。试试这个:GZipStream 和解压缩
You have to decompress the gzip-file, that step is missing. Try this: GZipStream and decompression