A ramble on HTTP protocol

Source: Internet
Author: User

Brief introduction


There are already a lot of good articles about HTTP. Some of the details of HTTP are better, so this article does not delve into the details of HTTP, but rather the elements of the HTTP protocol are categorized from a high and a more structured perspective.


Definition and History of HTTP


In a network. There are three issues to transmit data:


1. How the client knows the location of the content being asked.

2. When the client knows the location of the content, how to get the content asked.

3. What form the content of the request is organized in order to be recognized by the client.


For the web, there are three different techniques for answering the three questions above, namely the Uniform Resource Locator (URIS), the Hypertext Transfer Protocol (HTTP), and the Hypertext Markup Language (HTML). URI and HTML are very familiar to most web developers. HTTP protocols are too encapsulated in many web technologies to make HTTP the least familiar.


HTTP, as a transport protocol, is also evolving over time like HTML, and the current popular HTTP1.1 is the third version of the HTTP protocol.


HTTP 0.9


HTTP 0.9 is the first version of the HTTP protocol. is very weak. The request has only one line, for example:

Get www.cnblogs.com

From such a simple request body, no post method, no HTTP headers can be seen, that era of HTTP clients can only receive one type: Plain text. And if you don't get the information you asked for, there are no 404 500 errors.


Although HTTP 0.9 looks so weak, it has been able to meet the needs of that era.


HTTP 1.0


With the demand for Web applications after 1996, HTTP 0.9 has not been able to meet demand. The biggest change in HTTP1.0 is the introduction of the Post method, which makes it possible for clients to send data through an HTML table one-way server, which is also a foundation for Web applications. Another big change is the introduction of HTTP headers, which allow HTTP to return not only the error code, but also the contents of the HTTP protocol that are not limited to plain text, but to a range of formats, such as pictures, animations, and so on.


In addition, it allows for a connection that can be communicated multiple times after a TCP connection, although HTTP1.0 is turned off by default once the data is transmitted.


HTTP 1.1


May 2000, HTTP1.1 established. HTTP1.1 is not as revolutionary as HTTP1.0 for HTTP0.9. But there are also a lot of enhancements.


First, add host headers, such as Access to my blog:

Get/careyson http/1.1

Host:www.cnblogs.com

Only a relative path is required behind the get. This seems to be just like the sense of syntactic sugar, but in fact, this promotion makes it possible for a host on the web to have multiple domains. Otherwise, multiple domain names pointing to the same IP can cause confusion.


In addition, the range header is introduced, allowing the client to download only a portion of the content when downloading via HTTP, making it possible for multi-threaded downloads.


It is also worth mentioning that the HTTP1.1 default connection is always maintained, and this concept I will elaborate on below.


Network level of HTTP


All transmissions in the Internet are done through TCP/IP. HTTP protocol as the application layer protocol in TCP/IP model is no exception. The level of HTTP in the network is shown in Figure 1.


Figure 1. The level of HTTP in TCP/IP


As you can see, HTTP is a TCP protocol based on the transport layer, and TCP is an End-to-end connection-oriented protocol. The so-called end-to-end can be understood as the communication between processes to processes. So HTTP must first establish a TCP connection before starting the transmission, and the TCP connection process requires a so-called "three handshake". The concept is shown in Figure 2.


Figure 2. Three handshake of TCP connection


After the TCP three handshake, the TCP connection is established, and HTTP can be transmitted at this time. An important concept is connection-oriented, where HTTP does not disconnect TCP connections between transmission completion. In HTTP1.1 (set by the connection header) This is the default behavior. The so-called HTTP transmission completes us through a concrete example to look at.


For example, visit my blog, use fiddler to intercept the corresponding request and response. As shown in Figure 3.



Figure 3. Grab requests with fiddler and corresponding


As can be seen, although only to visit my blog, but the lock gets more than just an HTML, but the browser to HTML parsing process, if you find what you need to get, will again initiate HTTP request to the server to obtain, such as Figure 2 in the common2.css. The above 19 HTTP requests, which rely on only one TCP connection, are sufficient, which is called a persistent connection. It is also called an HTTP request completion.


HTTP requests (HTTP request)


The so-called HTTP request, that is, the Web client to send information to the Web server, this information consists of the following three parts:


1. Request Line

2.HTTP Head

3. Content


A typical request line, such as:

Get www.cnblogs.com http/1.1

The request line writing is fixed, consists of three parts, the first part is the request method, the second part is the request URL, the third part is the HTTP version.


The second part of HTTP headers in HTTP requests can be 3 HTTP headers: 1. Request headers 2. Common header 3. Entity headers (Entity header)


Generally, because a GET request often does not contain a content entity, there is no entity header.


The third part only exists in the POST request because the GET request does not contain any entities.


We intercept a specific post request to see these three parts, I put a button on a normal ASPX page, and when submitted, a POST request is generated, as shown in Figure 4.


Figure 4. HTTP requests are made up of three parts


HTTP request method


Although we are familiar with only get and post methods, there are actually a lot of HTTP request methods, such as: Put method, Delete method, head method, connect method, trace method. I'm not going to elaborate on this, Bing.


Here's a bit about get and post methods, and the difference between get and post is flying all over the web. But a lot of it doesn't speak for the point. The biggest difference between get and post is that the post has the third part: content. And get does not exist in this content. So just as the name of Get and post has it, get is used to fetch content from the server, although it is possible to send information to the server via QueryString, which violates the intent of getting, and the information in QueryString appears to be just an argument for obtaining the content in HTTP. And post is the way that the client sends content to the server side. So there is the third part of the request: content.


HTTP response (HTTP Response)


When the Web server receives an HTTP request, it does some processing based on the requested information (the processing may be simply a static return page, or it can be returned with a language such as asp.net,php,jsp), and an HTTP response is returned accordingly. HTTP responses are structurally similar to HTTP requests and are made up of three parts, respectively:


1. Status line

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.