Http request header header parsing

Request Headers:

The following picture is a header of a URL I visit: http://www.hzau.edu.cn, and analyze the functions and functions of each part according to specific examples.

 

 

Accept

Role: the media types that the browser can accept,

For example: Accept: text/html means that the browser can accept the type of server postback as text/html, which is the html document we often say,

If the server cannot return text/html type data, the server should return a 406 error (non acceptable)

Wildcard * for any type

For example, Accept: */* means that the browser can handle all types, (generally the browser sends this to the server)

 

Accept-Encoding:

Function: The browser declares the encoding method it receives, usually specifies the compression method, whether it supports compression, what compression method (gzip, deflate) is supported, (note: this is not just character encoding);

For example: Accept-Encoding: zh-CN,zh;q=0.8

 

Accept-Language

Function: The browser declares the language it receives. 

The difference between language and character set: Chinese is a language, and Chinese has multiple character sets, such as big5, gb2312, gbk, etc.;

For example: Accept-Language: en-us

 

Connection

For example: Connection: keep-alive When a web page is opened, the TCP connection used to transmit HTTP data between the client and the server will not be closed. If the client accesses the web page on the server again, it will continue to use the established one. Connection

For example: Connection: close means that after a 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 required when sending a request)

Function: The request header field is mainly used to specify the Internet host and port number of the requested resource, which is usually extracted from the HTTP URL.

For example: We enter in the browser: http://www.hzau.edu.cn

The request message sent by the browser will contain the Host request header field, as follows:

Host:www.hzau.edu.cn

The default port number 80 is used here. If the port number is specified, it becomes: Host: Specify the port number

 

Referer

When a browser sends a request to a web server, it usually brings a Referer to tell the server which page I am linking from, and the server can obtain some information for processing. For example, linking to a friend from my homepage, his server can count from the HTTP Referer how many users click on the link on my homepage to visit his website every day.

 

User-Agent

Role: Tell the HTTP server, the name and version of the operating system and browser used by the client .

When we log on to forums online, we often see some welcome messages that list the name and version of your operating system, the name and version of the browser you are using, which often makes many people feel amazing, in fact , the server application obtains this information from the User-Agent request header field. The User-Agent request header field allows the client to tell the server its operating system, browser and other attributes.

例如: User-Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; CIBA; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729; .NET4.0C; InfoPath.2; .NET4.0E)

 

 

In addition, when accessing some other URLs, some other fields in the Header of the request are listed below:

For example, when I log in to a website that requires a username and password to log in, there are fields in the Request Header that have not been mentioned above.

as the picture shows:

 

 

Cache-Control

The cache control of our web page is implemented by "Cache-control" in the HTTP header. Common values ​​are private, no-cache, max-age, must-revalidate, etc. The default is private. The roles of these values ​​are differentiated according to the way a page is revisited:

(1), open a new window

The value is private, no-cache, must-revalidate, then the server will be re-visited when a new window is opened. And if the max-age value (in seconds) is specified, then the server will not be revisited for the time within this value, for example:

Cache-control: max-age=5 (indicates that when this page is accessed again within 5 seconds, it will not go to the server)

(2), press Enter in the address bar

If the value is private or must-revalidate, the server will be accessed only the first time it is accessed, and it will not be accessed in the future.

The value is no-cache, then it will be accessed every time.

A value of max-age will prevent repeated visits until it expires.

(3), press the back button

If the value is private, must-revalidate, or max-age, it will not be revisited.

If the value is no-cache, the access is repeated every time

(4), press the refresh button

Repeat visit regardless of value

 

Cookie

Cookies are used to store some user information so that the server can identify the user's identity (common on most websites that require login). For example, a cookie will store some user's username and password. When the user logs in, a The cookie is used to store relevant information, so that the browser can verify that you are a legitimate user by reading the information of the cookie and verify that you are a legitimate user, thus allowing you to view the corresponding web page. Of course, the data in the cookie is not only in the above-mentioned scope, but also a lot of information can be stored in the cookie, such as sessionid and so on.

 

If-Modified-Since

Function: Send the last modification time of the cached page on the browser side to the server, and the server will compare this time with the last modification time of the actual file on the server. If the time is consistent, 304 is returned, and the client uses the local cache file directly. If the times are inconsistent, 200 and the new file contents are returned. After the client receives it, it will discard the old file, cache the new file, and display it in the browser.

Example: Mon, 17 Aug 2015 12:03:33 GMT

 

If-None-Match

Function: If-None-Match works with ETag, the working principle is to add ETag information in HTTP Response. When the user requests the resource again, the If-None-Match information (the value of ETag) will be added to the HTTP Request. If the server verifies that the ETag of the resource has not changed (the resource has not been updated), it will return a 304 status telling the client to use the locally cached file. Otherwise it will return a 200 status and a new resource and Etag. Using such a mechanism will improve the performance of the site

例如: If-None-Match: W/"3119-1437038474000"

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325938884&siteId=291194637