A comparison of the whole HTTP protocol Comments (1)

1. Concept

 1.1 Web Service

  Web Service (Web Services) use most of our daily service, all sites are based on Web services in the form of our presentation.

  • Web services are divided into server and client .
  • Common client that we use a variety of browsers (IE, Chorm, Safari, Firefox, Opera browser or command line) is the Web client.
  • The Web server is our Web site service visit. There are common Web server: IIS, Apache, Nginx, Lighttpd and so on. Different Web server on a different system platforms have their own advantages and disadvantages.

 1.2 HTTP protocol

  Hypertext Transfer Protocol (HTTP) is a communication protocol. It allows the Hypertext Markup Language (HTML) documents from the web server sent to the client .
  We usually browse the web, just enter the URL in the browser, the computer will be able to show what we want. But you have not thought about, in the end what happened after entering the URL it?
  Simply put, we say to the server: "Hey, buddy, I want to xxx", the server then what we want to send our computer revealed. When we apply resources to server, server to send us something this process is to follow (certain agreements No rules, no standards ), this agreement is the HTTP protocol.
  In other words, Wbe server and client interact via HTTP protocol.

  • HTTP is an application-layer protocol, composed of a request and response, it is a standard model for client server (CS Model). HTTP is a stateless protocol (next chapter will be mentioned).
  • In the Internet all transfers are done via TCP / IP. HTTP protocol as the protocol TCP / IP application layer model is no exception. HTTP protocol is usually carried over the TCP protocol, sometimes carried over TLS or SSL protocol layer, this time, it becomes that we often say HTTPS (HTTPS I will be mentioned later).
  • HTTP browsing is the main application, but this does not mean that it can only be applied to HTTP web browsing. HTTP is a protocol, as long as both sides abide by the protocol for communication, HTTP can have its uses. For example, we used the QQ, Thunder software, will use the HTTP protocol (also including other protocols).

2. The transfer process

  HTTP protocol (application layer) is supported on the TCP protocol (transport layer) above. While TCP is a connection-oriented protocol end. The so-called end can be understood as a process to communicate between processes. So HTTP in before the start of transmission , you first need to establish a TCP connection, and the process of TCP connections require so-called "three-way handshake." The following figure shows three-way handshake TCP connection.

 2.1 TCP three-way handshake (a connection)

the EMSP &; PS : Here is a great map, useful for understanding the TCP protocol. Although we are mainly talking about three-way handshake, but to understand the three-way handshake, four waved it is very simple.
Here Insert Picture Description

  • The first handshake: connection is established. The client sends a connection request segment, the SYN position 1, Seq is x; SYN_SEND client then enters a state waiting for acknowledgment from the server;
  • The second handshake: server receives a SYN segment. Server receives the client's SYN segment, the need for this SYN segment to confirm , setup Ack to x + 1 (Seq + 1) ; the same time, but also transmit their own SYN request message, the SYN position 1, Seq is Y; server all of the above information into a segment (i.e., segment SYN + ACK packet), the be sent to the client, when the server enters a state SYN_RECV;
  • Third handshake: the client receives the server SYN + ACK segment. Then set the Ack, sends an ACK segment is y + 1 to the server, after this segment has been sent, the client and server are entering ESTABLISHED state, complete the TCP three-way handshake.

  After the TCP three-way handshake to establish a TCP connection, this time can be transmitted HTTP .
  Four and three-way handshake is also waving the same principle, because of space limitations, here no longer explain. In the computer network column I will explain in detail the TCP / IP protocol.

 2.2 HTTP packets

  HTTP packet by the request packet and response packet composition. Both HTTP packets by the three-part composition: the start line , a header , the entity body .
Here Insert Picture Description

  2.2.1 Start Line

Request packet start line format :

Methods [space] [space] URL HTTP version

  • Methods : packet resource request sent to the specified resource request method , its role is to specify the requested resource as expected some kind of behavior .

  HTTP defines a number of methods, client communication, common approach to the Web server by following different ways:

GET Gets a resource from the server (typically a web page)
POST Submit data to the server (may create a new resource)
PUT Submit data to the server
DELETE Delete the specified resource
HEAD Only requests a page header information
  • The URL of : the URL of the link, locate resources position
  • HTTP version : There are HTTP / 1.0, HTTP / 1.1, HTTP / 2.0 version, which HTTP1.0 version uses more extensive.

Response packet start line format :

HTTP version [space] status code

  • Status code : is displayed to the client, the server state. For example: when we visited web pages often encounter 404 errors. Common status codes and their meanings are as follows:
200 Normal, successful request
301 Permanent movement, generally used domain redirect
304 Unmodified, generally used for caching
401 Disable access, unauthorized
403 Band access, usually represents has been certified, but do not have access
404 Resource not found
301 Internal server error
  2.2.2 neck (header)
  • It is used to illustrate some of the information the browser, server, or message body.
  • There may be several lines, may not be used
  • Each header row is the header field name, : , and a value
  • Each place has a header at the end of a blank line , header end flag
      HTTP header field is divided into four types: general header field , a request header field , the response header field , the entity header field .
    A map showing all fields: there is no longer one by one to explain the meaning of each field, are interested can go online to search ~~
    Here Insert Picture Description
  2.2.3 entity (body)
  • Request packet entity, what is the specific clients want.
  • Response message entity, is the client wants resources.

 2.3 browser demo

  We use Chorm browser, just open a web page (for example: www.meizu.com), right click, click [ check ], will come out the following interface, then click the order: Network-> www.meizu.com-> Headers, (if you do not see it on the page to reload )
Here Insert Picture Description
click to go to see these Headers. There are not very familiar with? This is what we just said HTTP packets. But the top and said there is something different, do not worry, click view source, view the display source. ( PS : because the browser displays the original view parsed-- view of parse meaning is the same, except that one source, one is parsed Tip: Some pages do not view source this option)
Here Insert Picture Description
After that click below pictures, and then we just said as a message.
Here Insert Picture Description
While the response packet entity in the Response back inside. Here are just for everyone to look at the HTTP messages about appearance, it is no longer a specific explain.

3.HTTP protocol development history

HTTP / 0.9: protocol is very simple, only one command GET, HEADER no description information. Has been sent to the server closes the TCP connection.
HTTP / 1.0:

  • Added a lot of commands, such as: POST, HEAD, PUT and so on.
  • Increase the status code and header.
  • Multi-character set support, multi-part transmission rights, caching.

HTTP/1.1:

  • Persistent connections ( HTTP is connectionless, the next article will be mentioned ).
  • Pipeline (pipelining), pipeline technology mechanism on a plurality of connection without waiting for response http request can be sent continuously. But this may lead to head of line blocking problem, also, therefore, many browsers this feature turned off by default. (HTTP2 solved the problem).
  • Increase the host and some of the other commands. Host is the more important thing, his presence, in order to achieve multiple Web services can run on a single server. For example: www.a1.com, www.a2.com, www.a3.com, three DNS domain name translated by the IP are the same, but you can Host, to distinguish between different Web services on the same server.

HTTP/2:

  • All data in binary transmission.
  • Which is connected with a plurality of transmission requests are no longer needed in order to.
  • Header compression and improve the efficiency of push and other functions.

4. HTTP protocol a basic workflow

  A single HTTP transaction operation is known, its work process generally can be divided into four steps:

  • First, the client and the server TCP connection is required. Just click on a hyperlink, HTTP work begins
  • After the connection is established, the client sends a request to the server, the request packet format on top of already mentioned.
  • Server upon request, will send a response to the client, the top response packet format has already been mentioned.
  • The client receives the information returned by the server displayed by the browser on the user's display, then the client and server is disconnected.

  If an error occurs in the course of more than a step, then an error message will be returned to the client, with a display screen output. For users, these processes are done by the HTTP themselves, users simply click with the mouse, waiting for the information displayed on it.

5. Summary

  Above is the HTTP protocol's initial explanation , talking about little things, we hope to have a clear concept. I will then write the follow-up, some important features about the HTTP protocol, HTTPS, and so on.
  Article if inappropriate, please exhibitions ~ If you have questions, you can shout zone discuss Duck!

Published 14 original articles · won praise 25 · views 5367

Guess you like

Origin blog.csdn.net/weixin_43275558/article/details/104192187