An HTTP request message consists of four parts: the request line, the request header, the blank line, and the request data.
First, the request line
The request line consists of a request method, a URL, and an HTTP protocol version, separated by a space. Like Get/data/info.html http/1.1.
(1) Request method: is the HTTP use of the request method, such as the common Get/post
(2) HTTP protocol version: http1.0/http1.1
Difference: HTTP1.0 only one request and response can be sent for each connection, the request is closed, HTTP1.0 does not have a host field
HTTP1.1 in the same connection CAs transmits multiple requests and responses, multiple requests can overlap and simultaneously, HTTP1.1 must have the host field
Second, request the head
HTTP client programs, such as browsers, must indicate the type of request (usually get or post) when sending a request to the server. If necessary, the client program can also choose to send additional request headers. Most request headers are not required, except for content-length. Content-length must appear for the POST request.
The common Request header field meaning:
Accept: The MIME type acceptable to the browser
Accept-charset: Browser-acceptable character set
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.
Content-length: Represents the length of the request message body.
Host: The host name that the client is telling the server that it wants to access through this header. The host header domain formulates the Internet host and port number of the requesting resource, and must represent the location of the originating server or gateway that requested the URL. The http/1.1 request must contain the host header domain or the system will return with a 400 status code.
If-modified-since: The client tells the server through this header the cache time of the resource. Returns the 304 "not Modified" answer only if all the requested content has been modified after the specified time to return it.
Referer: The client tells the server through this header which resource is accessing the server (anti-theft chain). Contains a URL from which the user accesses the currently requested page from the page represented by the URL.
The contents of the User-agent:user-agent header domain contain the user information that made the request. Browser type, this value is useful if the content returned by the servlet is related to the browser type.
Cookies: This header allows the client to bring data to the server, which is one of the most important request header information.
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.
From: The email address of the requesting sender, used by some special Web client, is not used by the browser.
Connection: Whether to disconnect or remain connected after the request has been processed. 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.
The Range:range header field can request one or more child ranges of an entity. For example:
Represents the first 500 bytes: bytes=0-499
Represents a second 500 byte: bytes=500-999
Represents the last 500 bytes: bytes=-500
Represents the range after 500 bytes: bytes=500-
First and last byte: Bytes=0-0,-1
Specify several ranges at the same time: bytes=500-600,601-999
However, the server can ignore this request header, and if the unconditional get contains a range request header, the response is returned as a status code of 206 (partialcontent) instead of a (OK).
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.
Three, empty line
Its purpose is to tell the server to request the head end by a blank line.
Iv. Request Data
If the method field is get, the entry is empty, no data
If the Method field is post, it is usually the data to be submitted that is prevented here
For example, to use the Post method to submit a form, where the data in the user field is "admin", the password field is 123456, then the request data here is user=admin&password=123456, using & To connect the individual fields.
In general, the HTTP request message format is as shown
Here is the Post method, its request line URL end is usually no parameters, the parameters are placed in the newspaper style. The parameters of the Get method are placed directly in the request line URL, and the style is empty.
HTTP request message Structure