2076 4

CSC329 ยท 2076 ยท 5 marks

What is HTTP protocol? Define HTTP Request and Response.

What is HTTP protocol? Define HTTP Request and Response. [5]

Web TechnologyChapter 1: IntroductionHTTP

Quick answer

HTTP (Hyper Text Transfer Protocol) is the underlying protocol used by the World Wide Web. It defines how messages are formatted and transmitted, and what actions web servers and browsers should take in response to various commands.

HTTP Protocol: Request and Response

HTTP Protocol

Key characteristics of HTTP:

  • It is based on the client-server model where the client sends a request and the server sends a response.
  • HTTP is implemented over a TCP connection, ensuring reliable data transmission.
  • When a user enters a URL in a browser, an HTTP command is sent to the web server directing it to fetch and transmit the requested web page.

Working of HTTP (Request-Response Cycle)

The step-by-step working of HTTP is as follows:

  1. User enters a web address (URL) in the browser.
  2. Browser uses DNS to locate the IP address of the server.
  3. Browser opens a TCP connection to the server.
  4. Browser sends an HTTP Request over the connection.
  5. Server sends an HTTP Response over the connection.
  6. Browser displays the body of the response in the browser window.

HTTP Request

An HTTP Request is a message sent by the client (browser) to the server asking for a specific resource. It typically contains:

ComponentDescription
Request MethodType of action: GET, POST, PUT, DELETE, etc.
URLThe address of the resource being requested
HTTP VersionVersion of HTTP being used (e.g., HTTP/1.1)
HeadersAdditional information such as host, content-type, cookies
BodyData sent to the server (mainly used in POST requests)

Example of an HTTP Request:

GET /index.html HTTP/1.1
Host: www.example.com
Accept: text/html

HTTP Response

An HTTP Response is the message sent by the server back to the client after processing the request. It typically contains:

ComponentDescription
Status LineHTTP version and status code (e.g., 200 OK, 404 Not Found)
HeadersMetadata such as content-type, content-length, date
BodyThe actual content (HTML page, image, data, etc.)

Common HTTP Status Codes:

  • 200 OK - Request was successful
  • 404 Not Found - Requested resource not found
  • 500 Internal Server Error - Server encountered an error

Example of an HTTP Response:

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1024

<html>
  <body>Welcome to Example!</body>
</html>

Summary: HTTP is the foundation of data communication on the web. The client sends an HTTP Request specifying what resource it needs, and the server replies with an HTTP Response containing the requested resource or an appropriate error message.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.