This project is read-only.

Display field in the http request and response messages?

May 13, 2011 at 7:31 PM
Edited May 13, 2011 at 7:32 PM

I want to display all fields in httpdatagra, I use the following code.

 
using PcapDotNet.Packets;
using PcapDotNet.Packets.Http;


namespace Capture_Packet
{
    class HTTPheader
    {
        public System.Windows.Forms.TreeNode MakeHTTPTreeNode(Packet packet)
        {
            System.Windows.Forms.TreeNode httpNode = new System.Windows.Forms.TreeNode();
            HttpDatagram httpheader = packet.Ethernet.IpV4.Tcp.Http;
            //HttpRequestDatagram request = new HttpRequestDatagram();
            httpNode.Text = "Hypertext Transfer Protocol";
            if (httpheader.IsRequest)
            {
                  // httpheader.Header


              
                   
                    httpNode.Nodes.Add("Version: " + httpheader.Version.ToString());
                   // httpNode.Nodes.Add("Version: " +  reqyest.Version.ToString());
                    httpNode.Nodes.Add("Byte Length: " + httpheader.Header.BytesLength.ToString());
        
            }
         
            else if (httpheader.IsResponse)
            {
              
               // httpNode.Nodes.Add(httpheader.Header.ContentType);
              //  httpheader =new  HttpResponseDatagram();
                httpNode.Nodes.Add(httpheader.Header.ContentType.ToString());
                byte[] bodybyte = new byte[httpheader.Body.ToMemoryStream().Length];
                bodybyte = httpheader.Body.ToMemoryStream().ToArray();
                httpNode.Nodes.Add("Data: " + System.Text.Encoding.ASCII.GetString(bodybyte)); 
            }

            return httpNode;
        }
    }
}

 

But the code did not meet what I want, want you to help me. Thanks

May 20, 2011 at 3:21 PM

What does the code outputs and what is it you want?

May 24, 2011 at 4:27 AM
Edited May 24, 2011 at 4:27 AM

Many times, it's error. I wish you could give me an example (code) about display fields in the HTTP messages. Thanks

Many times, it's error. I wish you could give me an example (code) about display fields in the HTTP messageMany times, it's error. I wish you could give me an example (code) about display fields in the HTTP message
Jun 11, 2011 at 1:34 PM

// Verify that this is an HTTP packet

...

// Print HTTP fields.

foreach (HttpField httpField in packet.Ethernet.IpV4.Tcp.Http.Header)

{

  // Note that binary values won't look nice here.

  Console.WriteLine(httpField.Name + ": " + Encoding.ASCII.GetString(httpField.Value));

}

Jun 11, 2011 at 5:23 PM

Thank brickner!, but

Error: Error    4    Argument 1: cannot convert from 'System.Collections.ObjectModel.ReadOnlyCollection<byte>' to 'byte[]'  

Jun 11, 2011 at 6:12 PM

Right, I haven't tried to compile it.

Just add ToArray() on the value.

Jun 12, 2011 at 4:39 AM

Thank brickner! , but

I do not find toArray () on the value.

Jun 24, 2011 at 12:19 PM

Try to add using System.Linq.

 

See here: http://msdn.microsoft.com/en-us/library/bb298736.aspx