Response message in HTTP/1.1 protocol

Wednesday afternoon, August 30, 2023


Table of contents


overview

The response message of the HTTP/1.1 protocol consists of the following parts:

  • Status Line
  • Response Headers
  • Blank Line
  • Response Body

Note that the response headers are optional, while the status line and empty line are required.

Response message example

HTTP/1.1 200 OK
Content-Type: text/html
Content-Length: 1234
Date: Mon, 01 Mar 2021 12:00:00 GMT
Server: Apache/2.4.18 (Ubuntu)

<!DOCTYPE html>
<html>
<head>
  <title>Example Page</title>
</head>
<body>
  <h1>Welcome to Example Page!</h1>
  <p>This is a sample page.</p>
</body>
</html>

In this example,

The status line specifies the HTTP/1.1 protocol version, the status code is 200, and the status message is OK, indicating that the request is successful.

The response header contains fields such as Content-Type, Content-Length, Date and Server.

The response body is the content of an HTML page.

detail

Status Line : The status line contains the protocol version, status code and status message. Separate them with spaces. Example: HTTP/1.1 200 OK

Response header (Response Headers) : The response header contains meta information about the response in the form of key-value pairs. Each key-value pair occupies one line, and the key and value are separated by a colon (:). Common response headers include Content-Type (the content type of the response), Content-Length (the length of the response body), Date (the date and time of the response), and Server (the server software of the response).

Blank Line : The response header and response body are separated by a blank line to indicate the end of the response header.

Response Body : The response body contains the actual response content. The format of the response body depends on the content type of the response, such as HTML, JSON, XML, etc.

Guess you like

Origin blog.csdn.net/m0_61629312/article/details/132586585