Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
TCP HTTP Gzip字符串解压缩C#_C#_Http_Tcp_Gzipstream_Pcap.net - Fatal编程技术网

TCP HTTP Gzip字符串解压缩C#

TCP HTTP Gzip字符串解压缩C#,c#,http,tcp,gzipstream,pcap.net,C#,Http,Tcp,Gzipstream,Pcap.net,我正在做一个关于数据包监听的项目。我对gzip解压有问题。代码如下: private static string gzipDecompress(TcpDatagram tcp) { if (tcp.Http.Header != null) { MemoryStream ms = tcp.Http.ToMemoryStream(); byte[] bytearray = new

我正在做一个关于数据包监听的项目。我对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 "";
    }
私有静态字符串gzip解压缩(TcpDatagram tcp)
{
if(tcp.Http.Header!=null)
{
MemoryStream ms=tcp.Http.ToMemoryStream();
byte[]bytearray=新字节[tcp.Http.Length];
里德女士(拜特里,0,4);
if(位转换器.ToUInt16(字节数组,0)=0x8b1f)
{
Seek女士(0,SeekOrigin.Begin);
GZipStream zip=新的GZipStream(ms,CompressionMode.decompresse);
zip.Read(bytearray,0,bytearray.Length);
StringBuilder sB=新StringBuilder(按阵列长度);
for(int r=0;r

它给出了一个神奇的数字异常:我如何修复它,或者我的方法是否错误?

如果您正在解析HTTP响应中的第一个HTTP数据包,则应该使用
HttpDatagram.Body
获取该数据包中的HTTP正文

如果您正试图解析其他数据包,那么在解析HTTP正文之前,您可能应该首先进行TCP重构