HTTP--Request/Response structure

Source: Internet
Author: User

One: An HTTP request message consists of four parts: the request line, the request header, the blank line, the request data.

1. Request Line

1. Request Method: GET POST

2.URL Field

3.HTTP Version Field

2. Request Header

1.Accept: The MIME type acceptable to the browser.

2.accept-charset: The acceptable character set of the browser.

3.accept-encoding: How the browser can decode.

4.content-length: Indicates the length of the request message.

5.Host: The client tells the server that it wants to access the host name.

6.Cookie: Clients can bring data to the server, which is only one of the most important information .

3. Blank Line

1. His role is to tell the server to request header information to this end.

4. Requested data

1. If the method is GET, the item is empty. (data is in the URL address bar)

2. If the method is a post field, the data to be submitted is usually placed.

Two: Response message: response header, response line, response body.

1. Response lines

1. Protocol version

2. Status Code

2. Response header

1.Allow (support for those requested methods.) such as: Get Post)

2.content-type: Indicates what type of document belongs to. The general default is Text/plain. Typically specified as text/html

3.Date: The current GMT time.

4.Expires: Tells the browser how long to cache the loopback resource, 1 or 0 is not cached.

5.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.

6.Location: This header is used with the 302 status code to redirect the recipient to a new URI address. Indicates where the customer should go to extract the document. Location is not usually set directly, but through HttpServletResponse's Sendredirect method

7.Refresh: Tells the browser how often to refresh, in seconds.

8.Server: The server tells the browser server type through this header.

9.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.

10.transfer-encoding: Tells the browser the transfer format of the data.

11.www-authenticate: What type of authorization information should customers provide in the authorization header? This header is required in an answer that contains a 401 (unauthorized) status line.

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

13.setContentType: Set Content-type header. This method is used by most servlets.

14.setContentLength: Set Content-length header. This function is useful for browsers that support persistent HTTP connections.

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

3. Response body

1. may be pure data

2. May be an HTML page.

HTTP--Request/Response structure

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.