Cyrus Yip's blog

What Is HTTP

Cyrus Yip
Table of Contents

Introduction #

HTTP (Hypertext Transfer Protocol) is a protocol for transferring information, such as HTML files. It’s the foundation of data communication for the World Wide Web. In a typical HTTP session, the client (such as a browser) sends a request to the server, which sends back a response.

HTTP Request #

A typical HTTP request consists of:

  1. request line (request method, path, protocol version)
  2. request header
  3. empty line
  4. optional message body

Here is an example of HTTP request message (curl --verbose https://cyrusyip.org/en/):

1
2
3
4
GET /en/ HTTP/2
Host: cyrusyip.org
User-Agent: curl/8.10.1
Accept: */*

HTTP Request Methods #

HTTP request methods (also called HTTP verbs) indicate the purpose of the request and what to expect. Here are the common request methods:

HTTP Response #

A typical HTTP response consists of:

  1. status line (protocol version, status code, optional explanation of status code)
  2. response header
  3. empty line
  4. optional message body

Here is an example of HTTP response message (curl --verbose https://example.com/):

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
HTTP/2 200
age: 190635
cache-control: max-age=604800
content-type: text/html; charset=UTF-8
date: Mon, 28 Oct 2024 09:39:38 GMT
etag: "3147526947+gzip+ident"
expires: Mon, 04 Nov 2024 09:39:38 GMT
last-modified: Thu, 17 Oct 2019 07:18:26 GMT
server: ECAcc (sac/2571)
vary: Accept-Encoding
x-cache: HIT
content-length: 1256

<!doctype html>
<html>
<head>
content is stripped...
</head>

<body>
<div>
    <h1>Example Domain</h1>
    <p>This domain is for use in illustrative examples in documents. You may use this
    domain in literature without prior coordination or asking for permission.</p>
    <p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>

HTTP Status Codes #

HTTP status codes are three-digit numbers that indicate whether an HTTP request has been successfully completed. They are grouped in five classes:

Here are some commonly used HTTP status codes:

References #

Tags:

Comments powered by giscus. If comments are not loaded, giscus may be blocked by your Internet service provider.