HTTP protocol details

Source: Internet
Author: User
Tags response code website server

Concept:

HTTP protocol, that is, Hypertext Transfer protocol ). It is a data transfer protocol that defines the communication rules between browsers and the World Wide Web (WWW = World Wide Web) servers and transmits World Wide Web documents over the Internet.

HTTP is a transfer protocol used to transmit hypertext from the WWW server to a local browser. It makes the browser more efficient and reduces network transmission. It not only ensures that the computer transfers hypertext documents correctly and quickly, but also determines which part of the transmitted documents and which part of the content is first displayed (such as text before graphics.

HTTP is an application layer protocol consisting of requests and responses. It is a standard client server model. HTTP is a stateless protocol.

The HTTP protocol is usually carried over the TCP protocol, and sometimes on the TLS or SSL protocol layer. At this time, we often say HTTPS. As shown in:

The default http port number is 80, and the HTTPS port number is 443.

 

Brief history:

Its development is the result of cooperation between the World Wide Web Consortium and the Internet team IETF (Internet Engineering Task Force). They finally published a series of RFC, RFC 1945 defines HTTP/1.0. The most famous one is RFC 2616. RFC 2616 defines a common version of HTTP 1.1.

 

Features:

The HTTP protocol always initiates a request from the client, and the server returns the response. This restricts the use of the HTTP protocol and prevents the server from pushing messages to the client when the client does not initiate a request.

The main features of HTTP are as follows:
1. Supports the customer/Server mode. Supports basic and security authentication.
2. simple and fast: when a customer requests a service from the server, they only need to send the request method and path. Common Request methods include get, Head, and post. Each method specifies the type of contact between the customer and the server. Because the HTTP protocol is simple, the program size of the HTTP server is small, so the communication speed is fast.
3. Flexibility: HTTP allows transmission of any type of data objects. The type being transferred is marked by Content-Type.
4. Use non-persistent connections for HTTP 0.9 and 1.0: only one request is allowed for each connection. After the server processes the customer's request and receives the customer's response, the connection is disconnected. This method can save transmission time. HTTP 1.1 uses persistent connections: you do not need to create a new connection for each web object. A connection can transmit multiple objects.
5. Stateless: HTTP is stateless. Stateless means that the Protocol has no memory for transaction processing. The lack of status means that if subsequent processing requires the previous information, it must be re-transmitted, which may increase the amount of data transmitted each connection.

Stateless protocol:
The status of the Protocol indicates the ability to "remember" The transfer information during the next transmission.
HTTP does not maintain the information transmitted by this connection for the next connection, in order to ensure the server memory.
For example, if the customer closes the browser after obtaining a webpage, then starts the browser again and then logs on to the website, but the server does not know that the customer closes the browser once.
Because the Web server must face the concurrent access of many browsers, in order to improve the web server's ability to process concurrent access, when designing the HTTP protocol to require the Web server to send HTTP response messages and documents, do not save any status information of the Web browser process that sends the request. This may occur when a browser accesses the same object twice in just a few seconds, the server process will not accept the second service request because it has sent a response message to it. Because the Web server does not save any information about the web browser process that sends the request, HTTP is a stateless protocol ).

Request Information:
The request information includes the following:
● The request line, such as get/images/logo.gif HTTP/1.1, indicates to request the logo.gif file from the/imagesdirectory.
● (Request) header, for example, accept-language: En
● Empty rows
● The optional Message Body request line and title must end with <CR> <LF> (that is, press enter and then line feed ). The blank line must contain only <CR> <LF> and no other spaces. In HTTP/1.1, all request headers, except post, are optional.

 

Request Method:
HTTP/1.1 defines eight methods (sometimes called "actions") to indicate the different operation methods of resources specified by request-Uri:
Options-return the HTTP request methods supported by the server for a specific resource. You can also use the '*' request sent to the Web server to test the server's functionality.
Head-Requests the server for the same response as the GET request, but the response body will not be returned. This method can obtain metadata contained in the Response Message Header without transmitting the entire response content.
Get-sends a request to a specific resource. Note: The get method should not be used in operations that produce "Side effects", for example, in web app. One of the reasons is that get may be randomly accessed by web spider.
Post-Submit a Data Processing request to a specified resource (for example, submitting a form or uploading a file ). Data is contained in the request body. POST requests may result in creation of new resources and/or modification of existing resources.
Put-upload the latest content to the specified resource location.
Delete-the request server deletes the resource identified by request-Uri.
Trace-requests received by the echo server are mainly used for testing or diagnosis.
The connect-HTTP/1.1 protocol is reserved for proxy servers that can change connections to pipelines.
Patch: used to apply local modifications to a certain resource and add them to standard rf120089.
The method name is case sensitive. When the resource for a request does not support the corresponding request method, the server should return status code 405 (method not allowed ); when the server does not recognize or support the corresponding request method, status code 501 (not implemented) should be returned ).
The HTTP server should at least implement the get and head methods. Other methods are optional. In addition to the preceding methods, the specific HTTP server can also extend the custom methods.

Response Header:
The client sends a request to the server. The server responds with a status line. The response content includes: message Protocol version, success or error code, server information, entity metadata, and necessary entity content. According to the type of the response category, the server response can contain entity content, but not all responses have entity content.
The first line of the response header is also known as the status line. The format is as follows (the line marked by the Red Line ):
HTTP-version space status-code space reason-phrase CRLF
HTTP-version indicates the HTTP Version. For example, HTTP/1.1. Status-code is the result code, represented by three numbers. Reason-phrase is a simple text description that explains the specific cause of status-code. Status-code is used for automatic machine identification, and reason-phrase is used for manual Understanding. The first number of status-code indicates the response category, which may have 5 different values. The last two digits are not categorized. The first number of status-code indicates the type of the response. The next two parameters describe the specific status of the response. For details, see http status code.

Response Header domain
The server needs to pass a lot of additional information, which cannot all be placed in the status line. Therefore, you need to define a response header to describe the additional information. The response header field mainly describes the server information and request-Uri information.

 


Whenever you browse a Web page, your computer will obtain the requested data through a server using the HTTP protocol. Before the requested webpage is displayed in the browser, the website server that directs the webpage returns an HTTP header file containing a status code. This status code provides related conditions for the requested webpage. If everything is normal, a standard web page will receive a Status Code such as 200. Of course, our goal is not to study the 200 response code, but to explore the response code of the server header file that represents the error message, for example, the 404 code indicating "the specified webpage is not found.

 

Workflow:

An HTTP operation is called a transaction. The procedure can be divided into four steps:
1) First, the client and the server need to establish a connection. Click a hyperlink to start HTTP.
2) After a connection is established, the client sends a request to the server in the format of Uniform Resource Identifier (URL), Protocol version number, the mime information is followed by the request modifier, client information, and possible content.
3) after receiving the request, the server returns the corresponding response information in the format of a status line, including the Protocol version number of the information, a successful or wrong code, mime information is followed by server information, entity information, and possible content.
4) The information returned by the client receiving server is displayed on the user's display screen through a browser, and the client is disconnected from the server.
If an error occurs in one of the preceding steps, the error message is returned to the client and displayed. For users, these processes are completed by HTTP. Users only need to click and wait for the information to be displayed.

 


HTTP status code:
00: standard response to successful requests
301: This webpage is permanently transferred to another URL
302: the requested webpage is transferred to a new address, but the customer's access continues through the original URL address
304: the requested webpage has not been modified since the last request. When the server returns this response, no webpage content is returned.
404: a 404 error indicates that the server can be connected, but the server cannot obtain the requested webpage
500: failed to complete the request due to a server error
503: the server is unavailable due to overload or shutdown maintenance.

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.