HTTP request header and Response header summary

Source: Internet
Author: User
Tags character set http request requires port number apache tomcat advantage

1) Request (client-to-server [request])
GET (The requested way)/books/java.html (requested target Resource) http/1.1 (the protocol and version number that the request takes)
Accept: */* (the type of resource the client can receive)
Accept-language:en-us (language type received by the client)
Connection:keep-alive (maintaining connection between client and server)
host:localhost:8080 (destination host and port number of the connection)
Referer:http://localhost/links.asp (where ever)
user-agent:mozilla/4.0 (name of the client version number)
Accept-encoding:gzip, deflate (the type of compressed data that the client can receive)
If-modified-since:tue, Jul 18:23:51 GMT (Cache time)
Cookie (Information on client staging server)

Date:tue, 18:23:51 GMT (client requests server time)


2) Response (server-side client [response])
http/1.1 (Protocol and version number of the response) 200 (status code) OK (description information)
302 (client requests the server, but the server does not have the corresponding resources, the service side to the client to request another server, that is, the client two requests, redirection)
307 (the client requests the server, but the server does not have the corresponding resources, the service side requests again to find the other server, that is, the client one request, forwarding)
304 (client Request server, at this time the client cache, there is no need to download new content from the server, the server called the client to find the cache, optimization)
500 (client-requested resource, server exists, but error occurred at execution)
Location:http://www.baidu.com (page path where client access is required by the server)
Server:apache Tomcat (Web server end name for server)
Content-encoding:gzip (server can send compression encoding type)
content-length:80 (length of compressed data sent by the server)
CONTENT-LANGUAGE:ZH-CN (language type sent by the server)
content-type:text/html; charset=gb2312 (type of server sent and encoding used)
Last-modified:tue, 18:23:51 GMT (last modified time for the resource by the server)
Refresh:1;url=http://www.it315.org (server requires client to refresh after 1 seconds, and then access the specified page path)
Content-disposition:attachment; Filename=aaa.zip (server requires client to download files to open the file)
transfer-encoding:chunked (chunked pass data to client)
SET-COOKIE:SS=Q0=5LB_NQ; Path=/search (staging data sent by the server to the client)
Expires: -1//3 (server-side Disable client Cache page data)
Cache-control:no-cache (server-side prevents client from caching page data)
Pragma:no-cache (server-side prevents client from caching page data)
Connection:close (1.0)/(1.1) Keep-alive (maintains connections between client and server)
Date:tue, 18:23:51 GMT (server response time on client)



Accept: The MIME type acceptable to the browser.

Accept-charset: The acceptable character set of the browser.

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

accept-language: The type of language the browser wishes to use when the server is able to provide more than one language version.

Authorization: Authorization information, which typically occurs in an answer to the Www-authenticate header sent to the server.

Connection: Indicates whether a persistent connection is required. If the servlet sees the value here as "keep-alive", or sees the request using an HTTP 1.1 (HTTP 1.1 is persistent by default), it can take advantage of the persistent connection, when the page contains multiple elements (such as applets, pictures), Significantly reduce the time it takes to download. To do this, the servlet needs to send a content-length header in the answer, and the simplest implementation is to write the content to Bytearrayoutputstream first and then calculate its size before formally writing the content.

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

Cookie: This is one of the most important request header information

from: The email address of the requesting sender, used by some special Web client, is not used by the browser.

Host: The hosts and ports in the initial URL.

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

Pragma: Specifying a value of "no-cache" means that the server must return a refreshed document, even if it is a proxy server and has a local copy of the page.

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

user-agent: Browser type, this value 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 Internet Explorer to indicate screen size, color depth, operating system, and CPU type.




HTTP Response Header Overview (HttpServletResponse)

the HTTP response of a Web server is generally composed of a status line, one or more answer headers, a blank line, and a content document. Setting the HTTP answer header is often combined with the status code in the Set status line. For example, there are several status codes that indicate that the "document position has changed" is accompanied by a location header, while the 401 (unauthorized) status code must be accompanied by a www-authenticate header.

However, it is useful to specify the answer header even when there is no status code that has special meanings set. The answer header can be used to complete: Set a cookie, specify the date of modification, instruct the browser to refresh the page at a specified interval, declare the length of the document to take advantage of persistent HTTP connections, ... And so many other tasks.

The most common method for setting the answer header is the setheader of the HttpServletResponse, which has two parameters that represent the name and value of the answer header, respectively. Similar to setting the status code, the setup answer header should be done before any document content is sent.

The Setdateheader method and the Setintheadr method are specifically designed to set up an answer header that contains a date and integer value, which avoids the hassle of converting Java time to a GMT time string, which avoids the hassle of converting integers to strings.

HttpServletResponse also offers a number of settings

setContentType: Sets the Content-type header. This method is used by most servlets.

setcontentlength: Sets the content-length header. This function is useful for browsers that support persistent HTTP connections.

Addcookie: Set a cookie (there is no Setcookie method in the Servlet API, because the answer often contains multiple Set-cookie headers).

Also , as described in the previous section, the Sendredirect method sets the location header when the status Code 302 is set.

HTTP response Header Description:

allow: Which request methods are supported by the server (such as GET, post, etc.).

content-encoding: The Encoding (Encode) method of the document. The content type specified by the Content-type header can be obtained only after decoding. Using gzip to compress documents can significantly reduce the download time of HTML documents. Java's gzipoutputstream can be easily gzip compressed, but only on Unix Netscape and IE 4, ie 5 on Windows. Therefore, the servlet should check whether the browser supports gzip by looking at the accept-encoding header (that is, Request.getheader ("accept-encoding")). Returns the gzip-compressed HTML page for a browser that supports gzip, returning a normal page for another browser.

content-length: Indicates the content length. This data is only required if the browser is using a persistent HTTP connection. If you want to take advantage of the persistent connection, you can write the output document to Bytearrayoutputstram, look at its size when done, then put that value into the Content-length header and finally pass the Bytearraystream.writeto ( Response.getoutputstream () Send content.

Content-type: Indicates what MIME type the following document belongs to. The servlet defaults to Text/plain, but it usually needs to be explicitly specified as text/html. Because Content-type is often set up, HttpServletResponse provides a dedicated method Setcontenttyep.

Date: The current GMT time. You can use Setdateheader to set this header to avoid the hassle of converting the time format.

Expires: When you should think that the document has expired so that it is no longer cached.

last-modified: The last time the document was changed. The customer can provide a date through the If-modified-since request header, which is treated as a conditional get, and only documents that have been modified later than the specified time are returned, otherwise a 304 (not Modified) state is returned. Last-modified can also be set using the Setdateheader method.

Location : Indicates where the customer should go to extract the document. Location is usually not set directly, but by HttpServletResponse's Sendredirect method, which sets the status code to 302.

Refresh : Indicates how much time the browser should refresh the document, in seconds. In addition to refreshing the current document, you can also pass SetHeader ("Refresh", "5; Url=http://host/path ") lets the browser read the specified page. Note This functionality is usually done by setting the HTML page in the head area of the <meta http-equiv= "Refresh" content= "5; Url=http://host/path "> is implemented because automatic refresh or redirection is important for HTML writers who cannot use CGI or servlets. For Servlets, however, it is more convenient to set the refresh header directly. Note that the meaning of refresh is "refresh this page after n seconds or visit the specified page" instead of "refresh this page every n seconds or visit the specified page". Therefore, continuous refresh requires a refresh header to be sent each time, and sending a 204 status code prevents the browser from continuing to refresh, whether it is using the refresh header or the <meta http-equiv= "Refresh" ...>. Note that the refresh header is not part of the HTTP 1.1 formal specification, but rather an extension, but both Netscape and IE support it.

Server : Servers name. The servlet generally does not set this value, but is set by the Web server itself.

Set-cookie: Sets the Cookie associated with the page. The servlet should not use Response.setheader ("Set-cookie", ...), but should use the dedicated method Addcookie provided by HttpServletResponse. See below for a discussion of cookie settings.

www-authenticate: What type of authorization information should the customer provide in the authorization header. This header is required in an answer that contains a 401 (unauthorized) status line. For example, Response.setheader ("Www-authenticate", "BASIC realm=\" Executives\ ""). Note that the servlet generally does not handle this, but instead gives the Web server a special mechanism to control access to password-protected pages (for example,. htaccess).

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.