1. Request message description An HTTP request message is requested by the request
line), request header (header), blank lines, and request data 4 parts, gives the general format of the request message.
(1) Request line
The request line consists of 3 fields of the Request Method field, the URL field, and the HTTP protocol version field, separated by a space. For example, get/index.html
http/1.1.
The HTTP protocol request method has get, POST, HEAD, PUT, DELETE, OPTIONS, TRACE, CONNECT. The most common get methods and post methods are described here.
Get: Use the Get method when the client wants to read the document from the server. The Get method requires the server to place the URL-positioned resource in the data portion of the response message, which is sent back to the client. When using the Get method, the request parameter and the corresponding value are appended to the URL, using a question mark ("?" ) represents the end of the URL and the start of the request parameter, which is limited by the length of the pass parameter. For example,/index.jsp?id=100&op=bind.
Post: You can use the Post method when the client provides more information to the server. The Post method encapsulates the request parameters in the HTTP request data, appears as a name/value, and can transmit large amounts of data.
(2) Request head
The request header consists of a keyword/value pair, one pair per line, a keyword and a value separated by a colon ":". The request header notifies the server that there is information about the client request, and the typical request headers are:
User-agent: The type of browser that generated the request.
Accept: A list of content types that the client can identify.
Host: The hostname of the request, which allows multiple domain names to be located in the same IP address as the virtual host.
(3) Blank line
The last request header is followed by a blank line that sends a carriage return and a newline character, notifying the server that the request header is no longer available.
(4) Request data
The request data is not used in the Get method, but is used in the Post method. The Post method is useful for situations where a customer needs to fill out a form. The most commonly used request headers associated with request data are Content-type and content-length.
2, detailed
The HTTP request consists of three parts: the request line, the message header, and the request body.
The request line begins with a method symbol, separated by a space, followed by the requested URI and version of the Protocol, in the following format:
Method Request-uri http-version CRLF.
Where method means the request, Request-uri is a Uniform Resource identifier, http-version represents the HTTP protocol version of the request, CRLF indicates carriage return and newline (except for the CRLF at the end, a separate CR or LF character is not allowed).
There are several ways to request a method (all uppercase), as explained in each method.
Get: Request for the resource identified by the Request-uri.
Post: Appends new data to the resource identified by Request-uri.
HEAD: Request a response message header for the resource identified by Request-uri.
PUT: The request server stores a resource and uses Request-uri as its identity.
Delete: The request server deletes the resource identified by the Request-uri.
TRACE: Requests the server to echo received request information, primarily for testing or diagnostics.
CONNECT: Reserved for future use.
Options: Request the performance of the query server, or query for resource-related options and requirements.
Method names are case-sensitive. When a request is directed to a resource that does not support the corresponding request method, the server should return the status Code 405 (method not allowed), and the Status Code 501 (not implemented) should be returned when the server does not recognize or support the corresponding request method. The HTTP server should at least implement the get and head methods, and the other methods are optional. Of course, all methods support implementations should conform to the respective semantic definitions of the methods described below. In addition, in addition to the methods described above, a specific HTTP server can also extend a custom method.
3. HTTP Response message
The HTTP response is also made up of three parts: the status line, the message header, and the response body.
The status line format is as follows:
Http-version Status-code reason-phrase CRLF
Where http-version represents the version of the server HTTP protocol, Status-code represents the response status code sent back by the server, and Reason-phrase represents a textual description of the status code. The status code consists of three digits, the first number defines the category of the response, and there are five possible values.
1XX: Indicates that the request has been received and continues processing.
2XX: Success-Indicates that the request has been successfully received, understood, accepted.
3XX: Redirect--further action is required to complete the request.
4XX: Client Error--the request has a syntax error or the request is not implemented.
5XX: Server-side error-the server failed to implement a legitimate request.
A description of the common status code and status is described below.
OK: Client request succeeded.
Bad Request: Client requests have syntax errors and cannot be understood by the server.
401 Unauthorized: Request is not authorized, this status code must be used with the Www-authenticate header domain.
403 Forbidden: The server receives the request but refuses to provide the service.
404 Not Found: The request resource does not exist, for example: The wrong URL was entered.
Internal Server error: Unexpected errors occurred on the server.
503 Server Unavailable: The server is currently unable to process client requests and may return to normal after a period of time, for example: http/1.1 200
OK (CRLF)
Introduction to HTTP Request messages