What does a simple HTTP request and response look like?
This an example of what an HTTP request would look like if user were doing a “POST method” with a body with 13 characters (see HTTP methods):
POST /api/hello HTTP/1.1
Authorization: Basic dGVzdHVzZXIwMTpuZXRjb29s
Content-Type: text/html; charset=UTF-8
Host: localhost
Connection: keep-alive
Content-Length: 13
"hello world"
The body in this message is “hello world” but it could be the contents of a binary image or something.
This is what a typical HTTP response might look like:
HTTP/1.1 200 OK
Date: Mon, 27 Jul 2009 12:28:53 GMT
Server: Apache/2.2.14 (Win32)
Last-Modified: Wed, 22 Jul 2009 19:15:56 GMT
Content-Length: 88
Content-Type: text/html
Connection: Closed
<html>
<body>
<h1>Hello, World!</h1>
</body>
</html>
Notice the 200 code? This is an HTTP response codes.
The headers are ended with the line sequence \r\n which comes from IBM and earlier. The block of headers is ended in a double \r\n\r\n block.