HTTP1.1 First Knowledge

Source: Internet
Author: User

Http (Hypertext Transfer Protocol) is a stateless, application-level protocol based on the request-and-response pattern.

In version Http1.1, there is a persistent connection (persistent Connections) mechanism, which acts as the default for establishing connections in Http1.1. With this connection, the browser can send a request and receive a response after establishing a connection, and then continue to send the request and get a response again (without disconnecting). And the client can send multiple requests in succession without waiting for each response to arrive.

Http URL

Format:
http://host[:p Ort][abs_path]
HTTP means to locate network resources through HTTP protocol;

Host represents a legitimate Internet host domain name or IP address (in dotted decimal format);

Port is used to specify a port number, and the server host that owns the requested resource listens to the TCP connection for that port. If port is empty, the default port of 80 is used.

ABS_PATH Specifies the URI of the requested resource (Uniform Resource Identifier, Uniform Resource Identifier), and if Abs_path is not given in the URL, it must be given as a "/" when it is the request URI. Usually this work browser is done for us.

Http Request

The client requests access to the resource to the server by sending an HTTP request
The HTTP request consists of three parts: the request line, the message header, the request body

The request line begins with a method symbol followed by the request URI and version of the protocol, ending with CRLF (carriage return line). The request lines are separated by a space. Separate CR or LF characters are not allowed except as CRLF at the end, in the following format:
–method Request-uri http-version CRLF

method means the request; Request-uri is a Uniform resource identifier that identifies the resource to be requested, http-version represents the HTTP protocol version of the request, and CRLF represents a carriage return line. For example:
–get/index.html http/1.1 (CRLF)

HTTP request-Method

Method effect

Get request gets the resource identified by Request-uri
Post appends new data to the resource identified by Request-uri
HEAD request Gets the response message header for the resource identified by Request-uri
Delete Request server deletes the resource identified by 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 choices and requirements
PUT Request server stores a resource and uses Request-uri as its identity

The Get method is used to obtain information about the resource identified by Request-uri, and the common form is:
–get Request-uri http/1.1
• When we visit a webpage by entering the URL directly in the address bar of the browser, the browser uses the Get method to get the resources from the server

The Post method is used to send a request to the server, requiring the server to accept the data appended to the request. The Post method uses the most when the form is submitted
• Example of submitting a form using the Post method
post/login.jsp http/1.1 (CRLF)
Accept:image/gif (CRLF) (...)
Host:www.sample.com (CRLF) (...)
....
Cache-control:no=cache (CRLF)
(CRLF)
username=zhangsan&password=123456

The head method is almost the same as the Get method, and the difference is that the head method simply requests the message header, not the complete content. For the response part of the head request, the information contained in the HTTP header is the same as the information obtained through the GET request. Using this method, you can obtain information about the resources identified by Request-uri without transmitting the contents of the entire resource. This method is typically used to test the validity of hyperlinks, whether they can be accessed, and whether they have recently been updated, etc.

* In HTML, write get and post, not case-sensitive, but get and post in the HTTP protocol can only be uppercase, the other methods are the same.

Http response

After receiving and interpreting the request message, the server returns an HTTP response message;
Like an HTTP request, the HTTP response is also made up of three parts: the status line, the message header, and the response body.

The status line consists of the Protocol version, the status code in the form of the number, the corresponding state description, and the elements are separated by a space, and the CR or LF characters are not allowed except for the end of the CRLF (carriage return line) sequence. The format is as follows:
Http-version Status-code reason-phrase CRLF
Http-version represents the version of the server HTTP protocol, Status-code represents the response code sent back by the server, Reason-phrase represents a textual description of the status code, and CRLF represents a carriage return line, for example:
–http/1.1 OK (CRLF)

The status code consists of three digits that indicate whether the request is understood or satisfied, and the status description gives a short textual description of the status code;
The first number of the status code defines the category of the response, followed by two numbers without a specific classification. The first number has five possible values;
1XX: Indicates information-Indicates that the request has been received and continues processing
2XX: Success-Indicates that the request has been successfully received, understood, accepted
3XX: Redirect-A further action must be made to complete the request
4XX: Client Error-Request syntax error or request not implemented
5XX: Server-side Error-Server failed to implement legitimate request


Status Code Status Description Description:
OK Client Request succeeded
Error 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 server receives request, but refuses to provide service
404 Not Found Request resource does not exist, eg: the wrong URL was entered
The Internal server error server has an unexpected error that prevents the client's request from being completed

503 Server Unavailable Server is currently unable to process client requests and may return to normal after some time

HTTP1.1 First Knowledge

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.