HTTP Explained
HTTP is an asymmetric request-response client-server protocol as illustrated.
HTTP = Hyper Text Transfer Protocol
Characteristics
-
HTTP is a stateless protocol = the current request does not know what has been done in the previous requests.
Structure of Request = Header + Body
URL http://www.nowhere123.com/doc/index.html into the following request message:
GET /docs/index.html HTTP/1.1 Host: www.nowhere123.com Accept: image/gif, image/jpeg, */* Accept-Language: en-us Accept-Encoding: gzip, deflate User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1) (blank line)
***This example has no data being sent in body****
line 1: Request Type (above GET) with path to request and version of HTTP
line 2: Host sending request to
line 3: Accept: client telling server what MIME data type they will accept
line 4: Accept-Language: client telling server the language they want the response in
line 5: Accept-Encoding: client telling server what encoded formats they want the resonse in (if there is an encoding)
line 6: User-Agent: client telling server what kind of client software (e.g. browser,etc) that request is made on
line 7: blank line - separates header from body of request
line 8++++: the data (if any) that is being sent from client to server
The HTTP Request TYPE : GET, POST, PUT, DELETE and MORE
GET
|
POST
|
Structure of a HTTP Response = Header + Body
An example of the HTTP response message is as shown:
HTTP/1.1 200 OK Date: Sun, 18 Oct 2009 08:56:53 GMT Server: Apache/2.2.14 (Win32) Last-Modified: Sat, 20 Nov 2004 07:16:26 GMT ETag: "10000000565a5-2c-3e94b66c2e680" Accept-Ranges: bytes Content-Length: 44 Connection: close Content-Type: text/html X-Pad: avoid browser bug <html><body><h1>It works!</h1></body></html>
About the Response Header - will minimally contain the following
-
Content-type
- Use if script is sending data back to the browser... e.g. a newly generated HTML file.
- Example: Content-type: text/html
- OR Content-type: text/plain
- OR Content-type: image/jpeg
- OR Content-type: video/mpeg
- OR Content-type: image/gif
- You describe the content by the MIME types (see your book)
-
Location
- Use if script wants to open and load another existing document on its server
- Can list full URL or relative path information.
- Example: Location: http://newton.sci.csuhayward.edu/~login/cgi-bin
-
Status
- Used to send special status code back to the browser to influence how it should respond.
- Example: Status: 204 No Response
- This means the browser should not expect any input back from the server.
Additional HTTP Header Info - Allow, Content-Type, Cookies, and more
HTTP w/ Cookies Request + Response Example