HTTP message structure is quite similar to, but more sophisticated than the structure of SMTP message. 3 major sections are included in HTTP message; Request-Line or Response-Line, Message Header and Message Body.
HTTP Request Message:
METHOD /path-to-resource HTTP/version-number
[ optional request body ]
METHOD: Basic and Commonly Used Request Method are GET, HEAD and POST. Other less commonly used are PUT, DELETE, TRACE, OPTIONS, CONNECT.
Desire to visit a specific URI is translated by web browser to a HTTP request like below:
Translated HTTP Request:
GET /sj/index.html HTTP/1.1
Difference between GET and HEAD method
GET & HEAD Request Method are obligated to be implemented by all web servers, while other methods are optional. GET is commonly used for retrieving data, a quite normal interaction. HEAD is created for client side cache-support. When receiving HEAD Request, Web server only feedbacks HTTP response header infos which include Last-Modified Date and Time. Then Web Client can decide whether use local cached page or retrieve a fresh copy from the information source. Very similar to IMAP mechanism. It is quite useful for implementing Change-Tracking systems.
Difference between POST and GET method
POST has a Request Body portion, while A GET request does not have a Request Body portion and, was not required to have Message Header (Host) until the HTTP version 1.1, as virtual hosting need to be supported.
HTTP Response Message
HTTP/version-number status-code message
[ response body ]
Response Message can be in the form of below:
HTTP/1.1 200 OK
. . .
<TITLE>SJ’s Web Page</TITLE>
<H2 ALIGN=”center”>Welcome to Sviergn Jiernsen’s Home Page</H2>
. . .
HTTP header can be of great importance, as it enables sophisticated applications, establishing & maintaining sessions, setting caching policies, controlling authentication, implementing business logic. There are 4 major HTTP header categories.
HTTP Status Codes
100 Continue: Web client can initial a partially HTTP Request by including “Expect” Header. If Web server can satisfy the requirement in ‘Expect’ Header, it will response with status code of 100.
200 OK: The request is fulfilled, Standard response to HTTP request
201 Created: the request is fulfilled and results in a new resource created on Web Server accordingly.
301 Move Permanently
320 Move Temporarily
4xx Client Error
400 Bad Request: The request cannot be fulfilled due to bad syntax.
401 Unauthorized: authentication is required and has failed or has not yet been provided
403 Forbidden: The request was a valid request, but the server is refusing to respond to it, because the content is restricted.
404 Not Found: The requested resource could not be found but may be available again in the future. Subsequent requests by the client are permissible.
417 Expectation Failed
5xx Server Error
500 Internal Server Error: A generic error message, given when no more specific message is suitable.
501 Not Implemented: The server either does not recognize the request method, or it lacks the ability to fulfill the request.
502 Bad Gateway: The server was acting as a gateway or proxy and received an invalid response from the upstream server.
503 Service Unavailable: The server is currently unavailable (because it is overloaded or down for maintenance).Generally, this is a temporary state
504 Gateway Timeout: The server was acting as a gateway or proxy and did not receive a timely response from the upstream server.
Difference between HTTP POST & PUT
to be continued