HTTP receive problem

Feb 1, 2011 at 10:22 PM

Hi everyone

im sending an HTTP packet by using the following code

 

HttpHeader c = new HttpHeader(HttpField.CreateField("Host", "profile.ak.fbcdn.net"),
                    HttpField.CreateField("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10"),
                    HttpField.CreateField("Accept", "image/png,image/*;q=0.8,*/*;q=0.5"),
                    HttpField.CreateField("Accept-Language", "en-us,en;q=0.5"),
                    HttpField.CreateField("Accept-Encoding", "gzip,deflate"),
                    HttpField.CreateField("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7"),
                    HttpField.CreateField("Keep-Alive", "115"),
                    HttpField.CreateField("Connection", "keep-alive"),
                    HttpField.CreateField("Referer", "www.SWEmosul.com"));
                

                // Create the packets layers
                Packet packet =
    PacketBuilder.Build(DateTime.Now,
                        new EthernetLayer
                        {
                            Source = sourceMAC,
                            Destination = destinationMAC,
                        },
                        new IpV4Layer
                        {
                            Source = new IpV4Address(srcIP), // i use the correct IP
                            Destination = new IpV4Address(destIP),
                            Ttl = 64, Identification = 100, Protocol = IpV4Protocol.Tcp }, new TcpLayer { DestinationPort = 80, SourcePort = 55319, SequenceNumber = 33, AcknowledgmentNumber = 0, Window = (ushort)256 }, new HttpRequestLayer { Header = c, }); communicator.SendPacket(packet);


i receive the packet in the destination and using wireshark reveals that everything is correct and the header is present , but when i receive it in my c# program the header and body of the http packet are empty , when i write it to a file the file remains empty , when i print it on the console nothing is printed

finally i used the following code

 

 

private static void PacketHandler(Packet packet)
        {
            HttpDatagram http = packet.Ethernet.IpV4.Tcp.Http;
            PcapDotNet.Packets.Http.HttpRequestDatagram http2=(HttpRequestDatagram)packet.Ethernet.IpV4.Tcp.Http;       
           StreamWriter aa = new StreamWriter(@"d:\MyTest.txt"); aa.Write(http.Header);// it gives an empty file aa.Close(); Console.WriteLine(http.Length);// the length is displayed(358) which indicates the the packet is actually recieved foreach (HttpField x in http.Header) { Console.WriteLine(x); } }

 

when i used the (foreach) statement i got the following error on it ("Object reference not set to an instance of an object")

Please HEEEEEEELP , I've been struggling with this problem for days

Coordinator
Feb 4, 2011 at 9:39 PM

The header can't be parsed because you don't give the parameters for the first line of the request.

Please supply the Version, Uri and Method parameters to the HttpRequestLayer.

Feb 5, 2011 at 6:22 PM
Edited Feb 5, 2011 at 6:23 PM

it worked , thank you sooooo much Boaz , i was testing in a peer-2-peer manor so i didnt think those parameters will matter now

Now im gonna sleep , BEEEEEEEEEEEEED