This is the third day of my participation in the August More text Challenge. For details, see:August is more challenging

Borrow more text challenge to urge oneself in August, thank nugget!

Basic concepts and a simple primer

For Http, let’s start with the Wikipedia definition:

HyperText Transfer Protocol (HTTP) is an application-layer Protocol for distributed, collaborative, and hypermedia information systems [1]. HTTP is the basis of data communication on the World Wide Web. HTTP was originally designed to provide a way to publish and receive HTML pages. Resources requested over HTTP or HTTPS are identified by Uniform Resource Identifiers (URIs).

I find two key points in the above description:

  • Is a communication protocol that acts on the application layer.
  • You need to use a URI for identification.

On the basis of network related knowledge, you can look at my article, the knowledge is relatively detailed. Http is an application layer protocol and a specification for data transfer. What is A URI? Uris are uniform resource identifiers (URIs), which need to be distinguished from URLS (Uniform resource Locator), which are subsets of URIs.

The basics of HTTP

Request packet and response packet

When a client sends a request to the server, the server sends a response packet to the client.

The format of the request packet is as follows:

Method  Path  HttpVersion
key : value 
......
Copy the code

Method is the Method used to request data. Common examples are GET and POST. GET gets data from the server and does not change the server’s data, so the data requested by GET can be cached. POST is to submit data to the server, which changes the server’s data. The submitted data is usually stored in the Body, not in the URL, so it is more secure.

The format of the response packet is as follows:

HttpVersion responseCode responseMessage
key : value
Copy the code

The response packet is as follows:

HTTP / 1.1 200 OK 
Date: Sun, 10 Oct 2010 23:26:07 GMT
Server: Apache / 2.2.8 (Ubuntu) mod_ssl / 2.2.8 OpenSSL / 0.9.8 gLast-Modified: Sun, 26 Sep 2010 22:04:35 GMT
ETag: "45b6-834-49130cc1182c0"
Accept-Ranges: bytes
Content-Length: 13
Connection: close
Content-Type: text/html
Copy the code

Two, response code

The response code is processed by the server and tells the client the result of processing. Common response codes include the following types:

(1), 1 xx

This type of response represents the end of the request, but still needs to be processed. Usually a temporary response containing only the status line and some optional response headers.

(2), 2 xx

This is a common response code that indicates that the request has been received and understood by the server. For example, 200 indicates that the request succeeds.

(3), 3 xx

This type of response indicates that the client needs to take further action to complete the request. For example, 301 indicates that the requested resource has been moved and needs to be redirected.

(4), 4 xx

This type of status code represents an error on the client side. For example, a common 404 indicates that the requested resource was not found on the server. It is widely used when the server does not want to reveal why the request was rejected

(5), 5 xx

This type of status code indicates an error on the server. The error is not due to a client problem, but to an exception in the service that causes the server to fail to complete the request from the client.

Third, the Header

Header indicates the Header field in the request packet or response packet. Common Header fields are as follows:

  • Host: represents the domain name of the requested host
  • Content-Type: Indicates the data type
  • Content-Length: Indicates the length of data
  • Connection: Whether the link will be closed after the data transfer is complete. The default is keep-alive
  • Authorization: Relates to authorization
  • Cache-Control: Whether to cache data
  • Cookie : records the client status

Stateless protocols and cookies

HTTP is a stateless protocol, meaning that it does not store any information between the two parties. However, in some cases, some data on the client needs to be recorded, for example, user login status needs to be recorded in some scenarios. This requires the use of cookies, which the server uses to store some data on the client.

No graphics, is only a brief summary of knowledge points. See you in the next article about the graph!

In addition, because the level is limited, the wrong place is inevitable, rather misleading others, welcome big guy to correct! Code word is not easy, thank you for your attention! 🙏