The HTTP Protocol

  • Requires: a connection between client and server
  • Stateless: no login process, each request is independent
  • Simple format: request header, blank line, possible payload
  • Symmetrical: allows data to be sent and recieved
  • Very easy to implement but scales very well

Example HTTP Request

Note lines folded for display.

What do each of these headers mean? Which are required? Many are defined in the HTTP standard but others can be defined via the HTTP extension framework.

Example HTTP Response

Example HTTP POST Request

Note lines folded for display.

This is a POST request, note how the data is encoded in the request body.

Example HTTP GET Request

Note lines folded for display.

This is the same form submitted via a GET request, here the data is encoded in request URL. Note also the If-Modified-Since header in this request, sent because my browser has just asked for the same resource.

HTTP Redirect

Alternately

The HTTP redirect is a server response that can be used to indicate that a resource has moved to a new location. An alternate is to include the above meta tag in a page header to force a redirect from the current page.

HTTP Verbs

  • GET - get a resource, Idempotent
  • POST - send some data to a resource
  • HEAD - get headers for a resource
  • PUT - create a new resource
  • DELETE - delete a resource

Common HTTP Response Status Codes

Some notable response codes:

  • 200 OK - Request succeeded and everything went well
  • 301 Moved Permanently - Requested resource has moved and all future requests should be made to new location
  • 403 Forbidden - Response refused by server (even if request is valid)
  • 404 Not Found - Server could not find requested resource (though it may be available in the future)
  • 500 Internal Server Error - Generic error message response when server encountered an error

See also: full list of HTTP status codes

Resources

  • Use Live HTTP Headers in Firefox to view headers of requests that you make. Also available as a Chrome Extension.
  • Similarly, in Google Chrome, the Resources panel in the Developer tools allows you to view the request headers and content for each request that was made when you're looking at a page.
  • Wikipedia's entry on HTTP gives a good overview of the protocol.