Newline character

This is a discussion on Newline character within the Networking/Device Communication forums, part of the General Programming Boards category; In the literature I've been reading about HTTP, etc... I've become even more confused than I was before (though at ...

  1. #1
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913

    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,246
    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,892
    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,246
    For completeness then
    "HTTP/1.1 200 OK\r\n"

  5. #5
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    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,892
    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, 04:10 AM
  5. pipe
    By smart girl in forum C Programming
    Replies: 4
    Last Post: 04-30-2006, 09:17 AM

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