HTTP protocol-http features, requests, and responses

Source: Internet
Author: User
Tags http request

For more details please see w3c/http1.1 Official document, English original address HTTP protocol main features

Support client/server model (c/s)

Flexible

No connection: The meaning of no connection is to limit the processing of only one request per connection. When the server finishes processing the customer's request and receives the customer's response, the connection is disconnected, which saves the transfer time. (Most servers today support the Keep-alive feature, using a server to support long connections, to solve the problem of no connection)

Stateless: Stateless means that the protocol has no memory capacity for transactions, and the server does not know what the client state is. That is, after the client sends the HTTP request, the server will send us the data according to the request, and the information will not be logged after it is sent. (use cookie mechanism to maintain session, solve stateless problem) HTTP request

A request message from the client to the server includes a one-line request message, method, resource ID, and protocol version.

Request

= request-line section  5.1

* ((General-header

| Request-header

| entity-header) CRLF)

CRLF

[Message-body]
Request Line (Request-line)

The request line begins with the method, followed by the request Statistics Resource location address (Request-uri). The method is case-sensitive. Method

     Method     = "OPTIONS"

                             | "GET"

                             | "HEAD"

                             | "POST"

                            | "PUT"

                            | "DELETE"

                            | " TRACE "

                            |" CONNECT "|extension-method

The methods in this list are specified in the Allow header field. The return code of the server response always notifies the client whether the requested resource is allowed in the current method, because the set of allowed methods is dynamically changed. If the server understands but the request resource method is not allowed, the server returns 405, and if the server does not recognize the method, it returns 501 (not implemented). The Get and head methods must be supported by all ordinary servers, and other methods are optional. If you want to implement these methods, you must use the same semantic implementation. request URI

The request URI is a Uniform resource identifier that identifies the resource on the request.

        Request-uri    =  "*"     |    Absoluteuri    |    Abs_path    |    Authority   

The four options for Request-uri depend on the nature of the request. The asterisk "*" means that the request does not support a specific resource other than the server itself, and can only be used if the method is not applied to a specific resource. A simple example is as follows:

        OPTIONS    *        http/1.1

This absolute address (Absoluteuri) is necessary when a request is submitted to the agent, the proxy may ask to be forwarded again or construct a response request from a valid cache. Requesting resource identification (the Resource identified by a request)

The exact location of the requested resource is determined by the Request-uri and host header domains in the request.

If the source server does not allow the resource to be differentiated according to the different hosts requested, it ignores the value of the host header domain when it decides to identify the resource through the http/1.1 request. Request Header Domain request header fields

The request header domain allows the client to pass additional information about the request and the client to the server. These header fields act as the adornment of the request, which is equivalent to the parameter semantics of the program language method invocation.

    Request-header = Accept |    Accept-charset |    accept-encoding |    Accept-language |    Authorization |    Expect |    from |    Host |    If-match |    If-modified-since |    If-range |    If-unmodified-since |    If-none-match |    Max-forwards |    proxy-authorization |    Range |    Referer |    TE | UsEr-agent 
Request Data

To access a Web site using the Get method, the HTTP request message is:

    get/index.html    http/1.1 \ r \ n    Host:www.gduf.edu.cn \

    user-agent:mozilla/5.0    \ r \ n

    ACCEPT-LANGUAGE:CN */*    \ r \ n
HTTP Response

After the request message is received and resolved, the server sends an HTTP response message. Status Line

The first line of the response (Response) message is the status line, which includes the protocol version, the numeric status code, and the reason text description. The format is as follows:

result code and reason description
The result code (STATUS-CODE) is a 3-bit integer that is commonly used in programs. The reason description (resion-phrase) is the textual interpretation of the result code, which is shown to the human user. The first digit of the result code is the code for the HTTP response, and the following two digits describe the specific result under the large classification. The first digit has 1 to 5 a total of 5 values, categorized as follows:

-1xx: Information-Request received, continue processing

-2xx: Success-Information has been received, understood and accepted

-3xx:  Redirect-further action must be taken in order to complete the request

-4xx: Client Error-Request contains error syntax or cannot be satisfied

-5xx: Server error-the server could not complete an apparently valid request
Common Status Codes
 $ OK: Client request succeeded multiple Choices: The server can perform a variety of operations on the request. 

301 Moved Permanently: Permanent move, request page has been permanently moved to a new location 302 Found 303 See other: View other locations where the requestor should use a separate GET request for a different location to retrieve the response when the server returns this code    307 Temporary Redirect: Temporary redirect, the server currently responds to the request from a different location, but the requestor should continue to use the original location for subsequent requests. Bad request: Client requests have syntax errors and cannot be understood by the server 401 Unauthorized: Request Unauthorized 403 Forbidden: The server received the request but refused to service 404 Not Found: The request resource does not exist for the Internal server Err Or: Server Unexpected error 503 server unavaliable: The server is currently unable to process client requests and may return to normal after a period of time 

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.