The message of HTTP is divided into request message and response message, when a Web page is opened, the browser will initiate an HTTP request message, and the HTTP server will send back a response message after receiving the request.
Basic structure of the message
HTTP request and response messages are made up of three parts: the start line that describes the message, the header block that contains the attribute, and the optional body (body) part that contains the data.
There are some grammatical differences between the request message and the response message, and the following is the format of the request message:
<method> <request-URL> <version>
The following is the format of the response message:
<version> <status> <reason-phrase>
1) Approach (method)
The action that the client wants the server to perform on the resource.
2) Request URL (Request-url)
Name the requested resource, or the full URL of the URL path component.
3) version (Ersion)
The HTTP version used for the message, in the format:
Http/<major>.<minor>
The 1.1 version is currently in use.
4) State Code (status)
Describes what happens during a request.
5) Reason phrase (reason-phrase)
The readable version of the status code is only meaningful to humans.
6) Header (header)
http/1.1 requires a valid request or response message to contain a specific header, each header contains a name, followed by a colon (:), followed by an optional space, followed by a value, and finally a newline (CRLF). The header ends with a blank line.
7) Entity (Entity-body)
Contains data frames consisting of arbitrary data, which can contain no entity parts.
Here is a specific example of requesting a message:
Get/test/hi-there.txt http/1.1accept:text/*host:www.joes-hardware.com
Response message:
http/1.1 okcontent-type:text/plaincontent-length:19hi! I ' m a message!
MethodCommon HTTP methods include the following:
Get: Get a copy of a document from the server
HEAD: Get the document header from the server only
POST: Send data to the server that needs to be processed
Put: Store the body portion of the request on the server
TRACE: Tracking of messages that may go through a proxy server to the server
Options: Decide which methods can be executed on the server
Delete: Delete a document from the server
Note Not all methods are implemented by each server.
Status codeThe status code is used to tell the client what happened, and the status code is categorized as follows:
100~199: Information Tips
200~299: Success
300~399: redirect
400~499: Client Error
500~599: Server Error
Some of the most common status codes are listed below:
OK: Success. All requested data is in the response body
401 Unauthorized: You need to enter a user name and password
404 Not Found: The server cannot find the resource corresponding to the requested URL
FirstThe header is a list of some name/value pairs that add some additional information to the request and response messages.
The HTTP specification defines several header fields, and the application can invent its own header at will. The HTTP header can be divided into the following categories:
1) General header;
-Can be present in the request message or in the response message
2) Request header;
3) response header;
4) Entity header;
-Describe the length and content of the subject, or the resource itself
5) Extension header.
--New header not defined in the specification
The usual headers are as follows:
DATE:TUE,3OCT 1997 02:16:03 GMT------Server generates a response date
content-length:15040 the body part of the------entity contains 15040 bytes of data
Content-type:image/gif the body part of the------entity is a GIF image
accept:image/gif,image/jpeg,text/html------Client can receive GIF pictures and JPEG images as well as HTML
The long header line can be divided into multiple lines, improve readability, and have a Space or tab (tab) in front of each line, such as:
Server:test Server
Version------Start with a space or tab
HTTP request and Response 1: Overview