HTTP
HTTP
Protocol(HTTP)
What is Hypertext?
⚫ Hypertext is a text that contains links to other texts(present
in same or different document).
⚫ By selecting a link, you are able to jump immediately to
another part of the document or even to a different
document.
⚫ In the WWW, links can go not only from one document to
another, but from one computer to another.
⚫ Browser is required to view and navigate hypertexts.
⚫ HTML language is used to create it.
HyperText Transfer Protocol
⚫ It is a protocol used by WWW for data communication
between web client (browser) and web server.
⚫ HTTP protocol defines how messages are prepared and
transmitted during web client and web server
communication.
⚫ It also defines what actions web server and browser should
take in response to various commands.
⚫ HTTP is a TCP/IP based communication protocol that is
used to deliver data which may be HTML files, image
files, query results, etc. on the web.
HTTP Protocol:Request & Response
⚫ HTTP is based on the client-server architecture model and
a stateless request/response protocol that operates by
exchanging messages across a reliable TCP/IP connection.
Client-Server Model
⚫ Web Client
⚫ It communicates with web server using a set of rules
(specified by HTTP protocol).
⚫ It uses HTTP protocol to communicate with the web server
to access resources specified by the URL.
⚫ Web server
⚫ It waits for incoming requests, process the requests, identify
the correct resource and finally responds with the desired
resource.
HTTP Protocol:Request & Response
⚫ HTTP is based on the client-server architecture model and
a stateless request/response protocol that operates by
exchanging messages across a reliable TCP/IP connection.
⚫ HTTP client (Web browser)
⚫ HTTP client is a program that establishes a connection to a
server for the purpose of sending one or more HTTP request
messages.
HTTP Protocol:Request & Response
⚫ HTTP server (web server)
⚫ It is a program that accepts connections in order to serve
HTTP requests by sending HTTP responses messages.
⚫ Response Message
⚫ In response to the request message, a response message is sent by a
server to the client.
HTTP Request Message
A request message consists of the following parts :
⚫ A request line
⚫ A header
⚫ An empty line
⚫ An optional body
HTTP Request Message
⚫ Request Line
⚫ It consists of three parts : Request type, URL, and HTTP
version.
⚫ Two consecutive parts are separated by a space.
⚫ Request type : is the type of request a client wants to send.
HTTP Request Message
⚫ Header fields
⚫ This is a collection of optional lines allowing additional
information about the request and/or the client (browser,
operating system, etc.).
⚫ Each of these lines is composed of a name describing the
header type, followed by a colon (:) and the value of the
header.
⚫ Body of the request : This is a collection of optional lines
which must be separated from preceding lines by an empty
line.
HTTP Request Message
HTTP Request Commands
⚫ GET
⚫ Request for the resource located at the URL.
⚫ HEAD
⚫ Request for the header of the resource located at the specified
URL and not the content.
⚫ POST
⚫ Sends data to the program located at the specified URL.
⚫ PUT
⚫ Sends data to the specified URL
⚫ DELETE
⚫ Deletes the resource located at the specified URL.
HTTP Response Message
A HTTP response is a collection of lines sent by the
server to the browser.
It includes :
⚫ A status line
⚫ A response header
⚫ An empty line
⚫ Body of the response
HTTP Response Message
⚫ Status Line
⚫ This is a line specifying the protocol version used and the
status codes of the request being processed using a code and
explanatory text.
⚫ Response header
⚫ Body of the response
⚫ This contains the requested document.
HTTP Status codes
These are response codes given by web server to help identify the cause
of the problem.
⚫ 10x : Informational message
⚫ These codes are not used in version 1.1 of the protocol.
⚫ 20x : Success
⚫ These codes indicate the smooth running of the transaction.
⚫ 30x : Redirection
⚫ These codes indicate that resource is no longer in the location specified.
⚫ 40x : Error due to the client
⚫ These codes indicate that the request is incorrect.
⚫ 50x : Error due to the server
⚫ These codes indicate that there is an internal error in the server.
Example 1
⚫ This example retrieves a document. We use the GET
method to retrieve an image with the path
/usr/bin/image1. The request line shows the method
(GET), the URL, and the HTTP version (1.1). The
header has two lines that show that the client can
accept images in the GIF or JPEG format. The
request does not have a body. The response message
contains the status line and four lines of header. The
header lines define the date, server, MIME version,
and length of the document. The body of the
document follows the header.
Example 1