Read HTTP request headers

Source: Internet
Author: User
Tags character set html page http request

An HTTP client, such as a browser, must indicate the type of request (typically get or post) when sending a request to the server. If necessary, the client can also choose to send another request header. Most request headers are not required, except for content-length. Content-length must appear for post requests.

Here are some of the most common request headers:

Accept: The MIME type acceptable to the browser.

Accept-charset: Browser-acceptable character set.

Accept-encoding: The data encoding method that the browser can decode, such as gzip. The servlet can return a GZIP-encoded HTML page to a browser that supports gzip. In many cases this can reduce the download time by 5 to 10 times times.

Accept-language: The kind of language that browsers want to use when the server can provide more than one language version.

Authorization: Authorization information that usually appears in the answer to the Www-authenticate headers sent to the server.

Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "keep-alive" or if it sees that the request uses HTTP 1.1 (HTTP 1.1 By default for persistent connections), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time required for downloading. To do this, the servlet needs to send a content-length header in the answer, the simplest way to do this is to write the content to Bytearrayoutputstream, and then calculate its size before the content is formally written out.

Content-length: Indicates the length of the request message body.

Cookie: This is one of the most important request headers, see the discussion in the chapter "Cookie Processing" later.

From: Requests the sender's email address, which is used by some special Web client programs and is not used by browsers.

Host: Hosts and ports in the initial URL.

If-modified-since: Returns a 304 "not Modified" answer only if the requested content is returned after the specified date and after it has been modified.

Pragma: Specifies that the "No-cache" value indicates that the server must return a refreshed document, even if it is a proxy server and already has a local copy of the page.

Referer: Contains a URL in which the user accesses the currently requested page from the page represented by the URL.

User-agent: Browser type, which is useful if the content returned by the servlet is related to the browser type.

UA-PIXELS,UA-COLOR,UA-OS,UA-CPU: A nonstandard request header sent by some versions of IE to indicate screen size, color depth, operating system, and CPU type.

For a complete and detailed description of HTTP headers, see the HTTP specification for http://www.w3.org/Protocols/.

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.