Zero basic learning interface test-HTTP message structure

1. HTTP request / response message

1. HTTP communication process:

The client sends a request to the server, and the server returns a response to the client.

2. Message:

Message: Information exchanged between the HTTP client and server. It is divided into two parts : message header and message data .

Request message: The request information submitted by the client to the server.

Response message: The response information returned by the server to the client.

3. Request message structure:

As shown in the figure below: it consists of four parts: request line, request header, blank line, and request data.

image.png

3.1, request line: including request method, request URI and protocol version.

3.2. Request header: notify the server client of the request information. Key-value pairs appear , one pair per line, and keywords and values ​​are separated by a colon ":".

Common header fields:

Accept: The type of information acceptable to the client, such as text / html, application / xhtml + xml

Accept-Charset: Character set acceptable to the client, such as gb2312

Accept-Encoding: The encoding method accepted by the client, such as gzip.

Accept-Language: The language type accepted by the client, such as: zh-CN.

Authorization: credentials for HTTP authentication

Content-Length: Set the byte length of the request body. The get request can be absent. The post request must include this.

Host: Set the server domain name and TCP port number, http protocol, port 80 can be omitted

Referer: The client tells the server through this header which resource it uses to access the server, which is the anti-theft chain.

User-Agent: Contains the client information that made the request, browser type / version, etc., such as: Mozilla / 5.0 (Windows NT 10.0; Win64; x64)

Cookie: The client records information to determine the user's identity, and uses set-cookie when setting up the server.

Cache-Control: how to deal with cache, for example: Cache-Control: no-cache

From: The email address of the client.

Connection: Tell the server what connection the client wants to use, the values ​​are keep-alive and close

3.3, blank line: separate request header and request data

3.4. Request data: Not used in GET method, used in POST method. Generally store post parameters and parameter data .

image.png

4. Structure of response message:

Including status line, response header, blank line, response data

image.png

Second, the request method

1. The three most commonly used request methods:

get: request resources (request the specified page information and return response data)

post: Submit data to the server for processing requests (submit form, upload file), new data will be created or data will be modified / deleted.

head: Similar to the get request, but does not return response data, only the response header. ****** will use this to see server information, etc.

Three, status code

1. Function of status code:

Describe the results returned. Including whether the response information returned by the server is normal, whether the server is working normally, and errors that are notified.

2. Status code category:

1XX: Specify the client to perform certain actions

2XX: The request was processed successfully

3XX: Redirect

4XX: Client request error

5XX: server error

3. Common status codes:

200 The request was successful and the server successfully returned the content.

Note: The status code is 200, it does not mean that the returned response data must be correct (it must be the data we want to request), it only means that the server responded to the client request normally.

301 Permanent redirect

302 Temporary redirect

400 Request syntax error or parameter error

403 The server refused to execute the request

404 The server cannot find the requested resource

500 server failure can not provide service

503 The server is overloaded or down for maintenance, and can provide services after a period of time

Guess you like

Origin blog.51cto.com/14790982/2487580