Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Example Analysis of HTTP response header

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article shares with you the content of a sample analysis of HTTP response headers. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

The HTTP request header provides information about the request, response, or other sending entity. The header information of HTTP includes four parts: universal header, request header, response header and entity header.

HTTP response header information

The HTTP request header provides information about the request, response, or other sending entity.

In this section, we will introduce the HTTP response header information in detail.

Which request methods (such as GET, POST, etc.) are supported by the Allow server. The encoding (Encode) method of Content-Encoding documents. 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 easily do gzip compression, but only Netscape on Unix and IE 4 and IE 5 on Windows support it. Therefore, Servlet should check whether the browser supports gzip by looking at the Accept-Encoding header (that is, request.getHeader ("Accept-Encoding"), returning gzip-compressed HTML pages for browsers that support gzip, and normal pages for other browsers. Content-Length represents the length of the content. This data is needed only if the browser uses a persistent HTTP connection. If you want to take advantage of persistent connections, you can write the output document to ByteArrayOutputStream, check its size when finished, put this value in the Content-Length header, and finally send the content through byteArrayStream.writeTo (response.getOutputStream (). Content-Type indicates what MIME type the subsequent document belongs to. Servlet defaults to text/plain, but usually needs to be explicitly specified as text/html. Because Content-Type is often set up, HttpServletResponse provides a special method, setContentType. Date's current GMT time. You can use setDateHeader to set this header to avoid the hassle of converting time formats. When should Expires think that the document is out of date and stop caching it? The last change time of the Last-Modified document. The customer can provide a date through the If-Modified-Since request header, and the request will be treated as a conditional GET, and only documents whose change time is later than the specified time will be returned, otherwise a 304( Not Modified) status will be 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 through the sendRedirect method of HttpServletResponse, which also sets the status code to 302. Refresh indicates how long the browser should refresh the document, in seconds. In addition to refreshing the current document, you can also use setHeader ("Refresh", "5; URL= http://host/path")") to let the browser read the specified page. Note that this functionality is usually achieved by setting the < META HTTP-EQUIV= "Refresh" CONTENT= "5 HTML URL = http://host/path" > in the HEAD area of the HTML page, because automatic refresh or redirection is important for HTML writers who cannot use CGI or Servlet. However, for Servlet, it is more convenient to set the Refresh header directly. Note that the meaning of Refresh is "refresh this page or visit a specified page after N seconds", not "refresh this page or visit a specified page every N seconds". Therefore, a continuous refresh requires that one Refresh header be sent at a time, and sending a 204status code prevents the browser from continuing to refresh, whether using the refresh header or < META HTTP-EQUIV= "Refresh". >. Note that the Refresh header is not part of the formal specification of HTTP 1.1, but is an extension, but is supported by both Netscape and IE. Name of the Server server. Servlet generally does not set this value, but is set by the Web server itself. Set-Cookie sets the Cookie associated with the page. Instead of using response.setHeader ("Set-Cookie",...), Servlet should use the special method addCookie provided by HttpServletResponse. See the following discussion of Cookie settings. What type of authorization information should WWW-Authenticate customers provide in the Authorization header? This header is required in a reply that contains a 401 (Unauthorized) status line. For example, response.setHeader ("WWW-Authenticate", "BASIC realm=\" executives\ ""). Note that Servlet generally does not handle this, but instead lets the Web server's special mechanism control access to password-protected pages (for example, .htaccess). Thank you for reading! This is the end of this article on "sample Analysis of HTTP response headers". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report