[Share] Interface Test-Header Detailed Explanation

1. What is header

header: The header is a string sent by the server before the HTML data is sent to the browser using HTTP protocol. There needs to be a blank line between the header and the HTML file.

-----Baidu Encyclopedia

header is the header information carried when sending the request. Usually some authentication information: authentication/cookie, response data format: content-type and so on. Of course, the response data will also return some header information.

Second, the corresponding meaning of the header parameters

1、Request header:

User-Agent: Tell the Http server, the name and version of the operating system and browser used by the client (this is also the way to distinguish between the PC and the app)

The app side can also distinguish between Android and iOS as shown in the figure:
Insert picture description here

2. Clint header field:

Accept: The media type (MIME) that the browser can accept;

Accept-Charset: The character set acceptable to the browser;

Accept-Encoding: The browser declares the encoding method it accepts, the compression method, whether it supports compression, and what compression method it supports

Accept-Language: declare the language you accept

The role of the clint header field, the client and the server have to communicate, then the client has to declare to the server the method of communication (User-Agent), the language of communication (Accept-Language), and the font of communication (accept-Encoding) , The content accepted by the client (accept), etc.

3. Cache header field:

If-Modified-Since: Send the last modified time of the browser-side cached page to the server. The server will compare this time with the modification time of the time file. The time always returns 304. Use the local cache data. If the time is inconsistent, it returns 200 and After receiving the new file content, the client will discard the old file and cache the new file and display it in the browser.

If-None-Match: Works with ETag. The working principle is to add ETag information to HTTP Response. When the user requests the resource again, If-None-Match information (ETag value) is added to HTTP Request. If the server verifies that the ETag of the resource has not changed (the resource has not been updated), the reward returns a 304 status to tell the client to use the local soul village file. Otherwise, it will return 200 status and new resources and Etage. Using such a mechanism will improve the new performance of the website.

Pragma: The function is to prevent the page from being cached. In the HTTP/1.1 version, it is exactly the same as Cache-Control:no-cache.

Cache-Control: Used to specify the caching mechanism followed by Response-Request, as follows:

Cache-Control: Public can be cached by any cache ()

Cache-Control: Private content is only cached in the private cache

Cache-Control: no-cache all content will not be cached

4. Cookie/Login header domain

Cookie: The most important header, the value of the reward cookie is sent to the HTTP server

5. Transport header field

Connection: the status of the connection, keep-alive when a web page is opened, the client and the server previously transmitted Http data to the TCP connection will not be closed, if the client accesses the server's web page again, it will continue to use the established connection ;Close When an open request is completed, the TCP connection used to transmit HTTP data between the client and the server will be closed. When the client sends the request again, the TCP connection needs to be re-established

Host (this header field is necessary when sending a request): The request header field is mainly used to specify the Internet host and port number of the requested resource. It is usually extracted from the HTTP URL. The port number in the host is omitted but it means the default 80 after port

6, Entity header field

Content-Length: the length of the data sent to the HTTp server

Content-Type: Internet media type

7、Miscellaneous头域

Referer: The server that provides the context information of the Request and tells the server which I am connecting from.

8. Ajax request method

The server determines whether the request request is synchronous or asynchronous. If there is X-Requested-With: XMLHttpRequest in the header, it is an asynchronous request. When X-Requested-With: null is a synchronous request

Three, interface testing tools

Interface test and interface document generation tool: apipost
Insert picture description here

Interface test and interface performance test tool: jmeter

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_47719617/article/details/111172091