Header header parsing for HTTP requests

Source: Internet
Author: User

Request Headers:

I visited a url:http://www.hzau.edu.cn header and analyzed the function and functions of each part according to the concrete example.

Accept

Role: The type of media that can be accepted by the browser side,

For example: accept:text/html represents the type of server postback that the browser can accept as text/html, which is what we often call HTML documents,

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

Wildcard * represents any type

For example, Accept: */* on behalf of the browser can handle all types, (the general browser to the server is the issue of this)

Accept-encoding:

Function: The browser declares itself to receive the encoding method, usually specifies the compression method, whether compression is supported, what compression method is supported (Gzip,deflate), (note: This is not a character encoding);

Example: accept-encoding:zh-cn,zh;q=0.8

Accept-language

Role: The browser affirms the language it receives.

Language and Character set differences: Chinese is a language, Chinese has a variety of character sets, such as BIG5,GB2312,GBK and so on;

Example: accept-language:en-us

Connection

Example: connection:keep-alive when a Web page opens, the TCP connection between the client and the server for transmitting HTTP data does not close, and if the client accesses the Web page on the server again, it will continue to use the established connection

For example: Connection:close represents the completion of a request, the TCP connection between the client and the server for transmitting HTTP data is turned off, and the TCP connection needs to be re-established when the client sends the request again.

Host (the header field is required when the request is sent)

Role: The request header domain is used primarily to specify the Internet host and port number of the requested resource, which is typically extracted from the HTTP URL

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

In the request message sent by the browser, the host Request header field is included, as follows:

Host:www.hzau.edu.cn

The default port number 80 is used here, and if a port number is specified, it becomes: Host: Specify port number

Referer

When the browser sends a request to the Web server, it usually takes Referer and tells the server which page link I took from, and the server can get some information for processing. For example, if you link to a friend from my home page, his server will be able to count the number of users who click on the link on my page to visit his website from HTTP Referer.

User-agent

Role: tells the HTTP server which client uses the name and version of the operating system and browser.

When we go online to the forum, often see some welcome information, which lists the name and version of your operating system, the name and version of the browser you are using, which often makes a lot of people feel very magical, in fact, The server application obtains this information from the User-agent request header domain user-agent The request header domain allows the client to tell the server about its operating system, browser, and other properties.

For example: 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)

Also, 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 Web site that requires a username and password, the request header contains fields that are not mentioned above.

Cache-control

The cache control of our web page is implemented by the "Cache-control" in the HTTP header, the common values are private, No-cache, Max-age, must-revalidate, etc., and the default is private. The effects of these values are differentiated according to the different ways in which a page is re-viewed:

(1), open a new window

The value is private, No-cache, Must-revalidate, and the server will be re-accessed when a new window is opened. If you specify a Max-age value (in seconds), the server is not re-accessed in the time within this value, for example:

Cache-control:max-age=5 (indicates that access will not go to the server within 5 seconds of accessing this page)

(2), enter in the address bar

A value of private or must-revalidate will only access the server on the first visit and will no longer be accessed at a later time.

The value is No-cache, which is accessed every time.

A value of max-age, the access is not repeated until it expires.

(3), press the Back button

The value is private, must-revalidate, Max-age, and is not re-accessed.

A value of No-cache, which is repeatedly accessed every time

(4), press the Refresh button

No matter what the value, it will be accessed repeatedly

Cookies

Cookies are used to store some user information so that the server can identify the user (most of the sites that need to be logged on are more common), such as a cookie that stores a user's username and password, and creates a cookie on the client when the user logs in to store the relevant information. This allows the browser to read the cookie information to the server to verify and pass after it will determine that you are legitimate users, allowing to view the corresponding page. Of course, the data in the cookie is not only the above range, but also a lot of information can be stored in the cookie, such as SessionID.

If-modified-since

Effect: The last modification time of the browser-side cache page is sent to the server, and the server compares this time with the last modification time of the actual file on the server. If the time is the same, then return 304, the client uses the local cache file directly. If the time is inconsistent, 200 and the new file contents are returned. After the client receives it, it discards the old files, caches the new files, and displays them in the browser.

For example: Mon, 12:03:33 GMT

If-none-match

Role: If-none-match works with the ETag and works by adding etag information to the HTTP response. When the user requests the resource again, the If-none-match information (the value of the ETag) is added to the HTTP request. If the server verifies that the etag of the resource has not changed (the resource is not updated), it returns a 304 status that tells the client to use the local cache file.  Otherwise, the 200 state and the new resource and ETag are returned. Using such a mechanism will improve the performance of your website

Example: if-none-match:w/"3119-1437038474000"

Header header parsing for HTTP requests

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.