Parsing HTTP Information

This is a discussion on Parsing HTTP Information within the C Programming forums, part of the General Programming Boards category; I am receiving a file from a server and would like to parse the HTTP information of the server but ...

  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    96

    Parsing HTTP Information

    I am receiving a file from a server and would like to parse the HTTP information of the server but am unsure as to how to do so. I would like to be able to tell what the content-length is and then set the variable appropriately. The same goes for Date and such. Thanks!

  2. #2
    Code Abuser
    Join Date
    Jan 2009
    Posts
    16
    Try grabbing the data from the server with telnet first. The data you get back makes it pretty obvious how you would go about parsing it. I.e. connect with telnet to a random webserver over port 80, and run the following commands (don't forget a double newline at the end)

    Code:
    GET /some/html/file.html HTTP/1.1
    Host: www.somehost.com

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    96
    I have done that part just fine but I want my program to break up the individual pieces so that when I read in say, Content-Length: I would know then to read the next item as the length of the content and assign it to the appropriate variable. I have variables for the Content-Length, The Error-Code return value by the http request, so on....I just would like to be able to parse the information.
    Last edited by NuNn; 02-11-2009 at 10:30 PM.

  4. #4
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    Well, each line of the header has \r\n appended to it i believe, so parse away!

    Keep in mind the header ends when you find \r\n\r\n

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 5
    Last Post: 06-01-2009, 07:54 PM
  2. Help with Parsing HTTP response from server
    By NuNn in forum C Programming
    Replies: 4
    Last Post: 02-19-2009, 02:02 PM
  3. Assignment Help !! (Student information system)
    By ashb in forum C++ Programming
    Replies: 6
    Last Post: 03-12-2005, 04:32 AM
  4. Going out of scope
    By nickname_changed in forum C++ Programming
    Replies: 9
    Last Post: 10-12-2003, 06:27 PM
  5. Special Allegro Information
    By TechWins in forum Game Programming
    Replies: 12
    Last Post: 08-20-2002, 11:35 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21