【发布时间】:2017-10-10 21:36:16
【问题描述】:
我正在做一个关于数据包监听的项目。我遇到了 gzip 解压缩的问题。有代码:
private static string gzipDecompress(TcpDatagram tcp)
{
if (tcp.Http.Header != null)
{
MemoryStream ms = tcp.Http.ToMemoryStream();
byte[] bytearray = new byte[tcp.Http.Length];
ms.Read(bytearray, 0, 4);
if (BitConverter.ToUInt16(bytearray, 0) == 0x8b1f)
{
ms.Seek(0, SeekOrigin.Begin);
GZipStream zip = new GZipStream(ms, CompressionMode.Decompress);
zip.Read(bytearray, 0, bytearray.Length);
StringBuilder sB = new StringBuilder(bytearray.Length);
for (int r = 0; r < bytearray.Length; r++)
sB.Append((Char)bytearray[r]);
zip.Close(); ms.Close(); zip.Dispose(); ms.Dispose();
return sB.ToString();
}
else
return "";
}
else
return "";
}
它给出了一个幻数异常,我该如何解决,还是我的方法不对?
【问题讨论】:
标签: c# http tcp gzipstream pcap.net