CSC329 ยท 2076 ยท 5 marks
What is HTTP protocol? Define HTTP Request and Response.
What is HTTP protocol? Define HTTP Request and Response. [5]
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:
- User enters a web address (URL) in the browser.
- Browser uses DNS to locate the IP address of the server.
- Browser opens a TCP connection to the server.
- Browser sends an HTTP Request over the connection.
- Server sends an HTTP Response over the connection.
- 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:
| Component | Description |
|---|---|
| Request Method | Type of action: GET, POST, PUT, DELETE, etc. |
| URL | The address of the resource being requested |
| HTTP Version | Version of HTTP being used (e.g., HTTP/1.1) |
| Headers | Additional information such as host, content-type, cookies |
| Body | Data 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:
| Component | Description |
|---|---|
| Status Line | HTTP version and status code (e.g., 200 OK, 404 Not Found) |
| Headers | Metadata such as content-type, content-length, date |
| Body | The actual content (HTML page, image, data, etc.) |
Common HTTP Status Codes:
200 OK- Request was successful404 Not Found- Requested resource not found500 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.