Title: HTTP
1HTTP
2Introduction
- Client-Server communication protocol
- Request-response
- Version 1.0
- Stateless
- Version 1.1 adds
- the ability to keep connections open
- virtual hosting
- etc
3Request/Response
- General Structure
- Start_LineltCRLFgt
- Message HeaderltCRLFgt
- ltCRLFgt
- Message BodyltCRLFgt
4More Details
- Start_line (Request or Response)
- Request
- MethodltSPgtRequest-URIltSPgtHTTP-VersionltCRLFgt
- Response
- HTTP-VersionltSPgtStatus-codeltSPgtResponse-PhraseltCRL
Fgt - Message Header
- Field_nameltSPgtField_value, Field_value
- Message Body
- Binary data
5HTTP Request Methods
- GET Retrieve the URL
- POST Give information to server
- HEAD Retrieve the header for the URL
- OPTIONS Request available options
- PUT Store document at specified URL
- DELETE Delete specified URL
- and many others
6Typical Request
GET /path/file.html HTTP/1.0 From
someuser_at_jmarshall.com User-Agent HTTPTool/1.0
blank line here
GET /path/file.html HTTP/1.1 Host
www.host1.com80 blank line here
7The GET Method
- Retrieves a URL
- General case is very simple
- Can send information along with URL
- URL?name1value1name2value2
- No Message Body
8The POST Method
- Send information in the Message Body
- Information is free format
POST /path/script.cgi HTTP/1.0 From
frog_at_jmarshall.com User-Agent HTTPTool/1.0
Content-Type application/x-www-form-urlencoded
Content-Length 32 homeCosbyfavoriteflavorf
lies
9The HTTP Response
- Status-Line
- HTTP-Version Status-Code Response-Phrase
- Headers
- Content-Type mime-type
- Blank line
- Message Body
10Status Line
- The HTTP version is in the format "HTTP/x.x".
- The status code is meant to be computer-readable
the reason phrase is meant to be human-readable,
and may vary. - The status code is a three-digit integer
- 1xx indicates an informational message only
- 2xx indicates success of some kind
- 3xx redirects the client to another URL
- 4xx indicates an error on the client's part
- 5xx indicates an error on the server's part
11Some Status Codes
- 200 OK
- The request succeeded, and the resulting resource
(e.g. file or script output) is returned in the
message body - 404 Not Found
- 301 Moved Permanently
- 302 Moved Temporarily
- 303 See Other (HTTP 1.1 only)
- The resource has moved to another URL (given by
the Location response header), and should be
automatically retrieved by the client. This is
often used by a CGI script to redirect the
browser to an existing file. - 500 Server Error
12Typical Response
HTTP/1.0 200 OK Date Fri, 31 Dec 1999 235959
GMT Content-Type text/html Content-Length
1354 lthtmlgt ltbodygt lth1gtHappy New
Millennium!lt/h1gt (more file contents) . . .
lt/bodygt lt/htmlgt
13HTTP 1.1
- Additional Headers
- Sockets stay open
- Time-out connection, or
- Connection close header
- Host header is required
- Host www.servername.domain
- Chunked Data