[Android] classic explanation of HTTP protocol

Source: Internet
Author: User

Original post address: http://blog.sina.com.cn/s/blog_62f987620100neph.html
[Android] classic explanation of HTTP protocol

(17:08:22)Reprinted

Tags:

Android

 

HTTP

 

Macrocheng

 

Get

 

Post

 

Put

 

Head

 

Delete

 

Traceconnect

 

Options
Category: Android
1. What is HTTP? HTTP is an application layer protocol. HTTP is short for Hypertext Transfer protocol. HTTP can transmit data between the client and the server through the TCP protocol at the transport layer. HTTP is mainly used for data exchange between Web browsers and web servers. When we use IE or Firefox to browse or download web resources, input http: // host: Port/path in the address bar, the four letters starting with HTTP are equivalent to notifying the browser to use the HTTP protocol to communicate with the server specified by the host. The HTTP protocol was born in the early 1990s S. The first widely used version was HTTP Protocol 9. The original version is very simple. It only sends a very simple request to the server, and the server will return a very simple response and corresponding HTML text. In the subsequent http1.0, many features not available in https9 were added, such as resource relocation and a large number of status Response codes. In the latest http1.1, http1.0 has been further improved. In addition to adding some request methods, the biggest improvement is to keep the HTTP connection status. This is very beneficial for some applications that frequently transmit data. As the HTTP protocol has reached its goal, W3C, which is responsible for standardizing, has stopped improving HTTP (http-related protocols or extensions have not been stopped, http1.1 is the last version of the HTTP protocol. Whether you are engaged in network program development, web development, or website maintenance personnel, you must have a deep understanding of the HTTP protocol. Therefore, HTTP is not only the most widely used protocol on the Internet, but also a simple entry-level protocol in the application protocol family. All Web servers support HTTP without exception. This fully demonstrates that for those who develop network programs, especially those who develop various types of web servers, A thorough understanding of the HTTP protocol will have a direct impact on your developed HTTP-based system. The purpose of this article is not to explain the HTTP protocol. Therefore, we only discuss the main part of the HTTP protocol. If you are interested in the HTTP protocol and want to know more about the HTTP protocol, for more information about the HTTP protocol, see rfc2616 or www.w3c.org. Ii. How HTTP works HTTP uses the request/response method. Each time a client based on http1.0 sends a request to the server, the server returns a Response Message (including whether the request is correct and the requested data) to the client ), after confirming that the client has received the response message, the server closes the network connection (actually closing the TCP connection ). In this data transmission process, no historical information and status information are stored. Therefore, HTTP is also considered as a stateless protocol. Figure 1 depicts the communication process of http1.0.

Figure 1Communication Process of http1.0 ProtocolIn http1.0, when a web browser sends a request, it means that a request/response session has started. After the request and response are complete, the server immediately closes the connection. This session method is simple, but it brings about another problem. If an HTML or other web page accessed by the client browser contains other web resources, such as JavaScript files, image files, and CSS files, each time the browser encounters such a web resource, an HTTP session is created. If there are many such resources, it will increase the burden on the server and affect the efficiency of loading HTML and other Web Resources on the client browser. After improving and improving the above defects, the http1.1 Protocol entered our sights. The biggest difference between http1.1 and http1.0 is that persistent connections are supported. After the client connects to the server using the http1.1 protocol, the server returns the initiative of closing the client connection to the client. That is, after the client sends a request to the server and receives a response, as long as you do not call the close method of the socket class to close the network connection, you can continue to send HTTP requests to the server. When HTML contains other web resources, the browser can use the same network connection to download these resources, which can greatly reduce the pressure on the server. Figure 2 demonstrates this process. Figure 2Communication Process of http1.1 ProtocolIn addition to persistent connections, http1.1 also extracts http1.0 request methods from the original three (get, post, and head) extended to eight (options, get, Head, post, put, delete, trace, and connect ). In addition, many request and response fields are added, such as the persistent connection field connection. This field has two values: close and keep-alive. If connection: Close is used, the persistent connection function of http1.1 is disabled. To enable the persistent connection function of http1.1, you must use connection: keep-alive, or do not add the connection field (because http1.1 is a persistent connection by default ). In addition, it also provides request headers and Response Headers related to identity authentication, status management, and cache.

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.