Thread: Newline character

  1. #1
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912

    Newline character

    In the literature I've been reading about HTTP, etc... I've become even more confused than I was before (though at least now I know about the problem) about how lines are terminated in HTTP messages (i.e. the character that represent the start of a new header, or a new section in the message). I know that different methods are used in differen't operating systems, but what is used in HTTP messages, and how is it represented in C?

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    In HTTP, a line is terminated by a carriage return followed by a newline character. In C, this is done by "\r\n". For instance, the first line in an HTTP request might look like:
    "HTTP/1.1\r\n"

  3. #3
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    The line terminator in the headers is the crlf pair, represented in C as the string "\r\n".

    Edit: bithub beat me to it - but just to be annoying, I'll point out that this "first line" is not valid
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    For completeness then
    "HTTP/1.1 200 OK\r\n"

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Or "GET / HTTP/1.1\r\n".
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  6. #6
    Registered User
    Join Date
    Sep 2001
    Posts
    4,912
    Well since you're using HTTP 1.1, a Host header is required.

  7. #7
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    We were only posting first lines. There was no empty header line yet, so I could have posted the Host header later.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Errors including <windows.h>
    By jw232 in forum Windows Programming
    Replies: 4
    Last Post: 07-29-2008, 01:29 PM
  2. sequential file program
    By needhelpbad in forum C Programming
    Replies: 80
    Last Post: 06-08-2008, 01:04 PM
  3. Interpreter.c
    By moussa in forum C Programming
    Replies: 4
    Last Post: 05-28-2008, 05:59 PM
  4. get wide character and multibyte character value
    By George2 in forum C++ Programming
    Replies: 27
    Last Post: 01-27-2008, 05:10 AM
  5. pipe
    By smart girl in forum C Programming
    Replies: 4
    Last Post: 04-30-2006, 09:17 AM