HTTP request and Response message Basics

Source: Internet
Author: User

An HTTP request message (Http://en.wikipedia.org/wiki/List_of_HTTP_header_fields)

The request message consists of three parts: the request line, the request header, and the request body.

Request Line: Request method (such as post), Request URL address (and request header host property to compose full URL), HTTP protocol and version.

Request Header: Contains several properties in the format "property Name: Property value".

Request body: A formatted string encoded as a Param1=value1&param2=value2 key-value pair that hosts data for multiple request parameters. In addition to the request body, the request URL can also pass the data through "? Param1=value1&param2=value2".

Common HTTP request Header properties:

Accept: The response type that the client receives, which can be a value of one or more MIME types.

Cookie: A client-side cookie that can place jsessionid in a cookie.

Referer: Indicates which URL the request came from.

Cache-control: Specifies the caching mechanism that must be adhered to throughout the request response chain.

Content-length: The number of bytes of the request body.

The server side reads the request header through HttpServletRequest. Some of the typical request header properties, such as Cooke,locale and contentlength, have direct read APIs. For HttpSession, the value of Jsessionid in the request header cookie attribute is read, and the HttpSession object is obtained from the server-side of a session map based on Jsessionid for session management.

Two HTTP response messages

The HTTP response consists of three parts: the response line, the response header, and the response body.

Response Line: HTTP protocol and version, response status and description.

Response header: Also consists of multiple attributes.

Response Body: The returned resource.

Response Status: (Http://en.wikipedia.org/wiki/List_of_HTTP_status_codes)

1XX: Received the request, is processing and so on.

2XX: Processing success, processing completion, etc. If the success of the processing of the OK.

3XX: Redirect and so on. If 303 see other, redirect to location; 303 not Modified.

4XX: Error occurred, responsibility on client. such as 404 Not Found.

5XX: Error occurred, responsibility on the server side. such as the Internal Server Error.

Common HTTP Response Header properties:

Cache-control: Set the cache policy, access the resources again within the cache time should return content directly from the client cache, the implementation by the client implementation.

ETag: The specific version of the server resource, only under the unified URL, the comparison of the etag is meaningful.

Last-modified: The last modification date of the requested entity.

Location: A URL that lets clients redirect.

Set-cookie: The server sets the Cookie for the client.

The server writes the properties of the response header through the HttpServletResponse API. such as Cookie,location provides direct operation of the API.

HTTP request and Response message Basics

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.