简体   繁体   中英

How can I create HttpResponseDatagram and HttpResponseLayer in pcap.net

I cant create these objects in pcap.net

IpV4Datagram ip = packet.Ethernet.IpV4;
        TcpDatagram tcp = ip.Tcp;
        HttpDatagram http = tcp.Http;
     //   HttpResponseDatagram resdat=http.;  How can i create them?
     //   HttpResponseLayer resp;
if (tcp.Http.Body != null && http.IsResponse)
            body = resp.Body.ToString();

I'm trying to get HTTP Response Body from a tcp packet. If there is another way to do it can someone help?

In the Pcap.Net User Guide , there's a section about sending packets . In that section, there is an example on how to create HttpRequestLayer , and creating HttpResponseLayer is very similar.

  HttpRequestLayer httpLayer = new HttpRequestLayer { Version = HttpVersion.Version11, Header = new HttpHeader(new HttpContentLengthField(11)), Body = new Datagram(Encoding.ASCII.GetBytes("hello world")), Method = new HttpRequestMethod(HttpRequestKnownMethod.Get), Uri = @"http://pcapdot.net/", }; 

HttpResponseDatagram is creating by parsing an HTTP packet. For example, by doing

packet.Ethernet.IpV4.Tcp.Http

There's no simple way of creating a Datagram without parsing a packet.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM