The most basic content of HTTP, the interview is not yet?

2023.08.30

The most basic content of HTTP, the interview is not yet?


HTTP is a stateless protocol, which means that the server does not maintain state information about the client. So there is the emergence of Cookie and Session. And Cookie and Session are used to maintain state.

We all know that HTTP has always been the content that is often asked in interviews, and some problems about HTTP status codes encountered during development, so as to locate and solve problems. Let me talk about this knowledge about HTTP today.

HTTP

What is HTTP?

HTTP is called Hypertext Transfer Protocol (Hypertext Transfer Protocol, HTTP) is a simple request-response protocol, which usually runs on top of TCP. It specifies what kind of messages the client may send to the server and what kind of responses it may get.

Iteration of HTTP:

  • 0.9

The 0.9 protocol is a simple and fast protocol suitable for various data information, but it is far from meeting the needs of various applications that are developing day by day. The 0.9 protocol is a disorderly protocol for exchanging information, limited to text. Due to the inability to negotiate the content, in the handshake and agreement of the double post, there is no regulation on the content of the double post, that is, the picture cannot be displayed and processed.

  • 1.0

At the 1.0 protocol stage, that is, in 1982, Tim Berners-Lee proposed HTTP/1.0. In the continuous enrichment and development since then, HTTP/1.0 has become the most important transaction-oriented application layer protocol. The protocol establishes and tears down a connection for each request/response. Its characteristics are simple and easy to manage, so it meets everyone's needs and has been widely used.

  • 1.1

In the 1.0 protocol, the two parties specified the connection method and connection type, which has greatly expanded the field of HTTP, but there is not much consideration for the most important speed and efficiency of the Internet. After all, as the framer of the protocol, I didn't expect that HTTP would be so popular at that time.

  • 2.0

The predecessor of HTTP2.0 is HTTP1.0 and HTTP1.1. Although there were only two versions before, the protocol specifications contained in these two versions are huge enough to give any experienced engineer a headache. New versions of network protocols do not immediately replace older versions. In fact, 1.0 and 1.1 have been co-existing for a long time, which is determined by the slow update of network infrastructure.

How HTTP works

HTTP is based on the client/server model and is connection-oriented. Typical HTTP transaction processing has the following process:

  • The client establishes a connection with the server;
  • The client makes a request to the server;
  • The server accepts the request and returns the corresponding file as a response according to the request;
  • The client and server close the connection.

In fact, it can also be understood as the following five steps

  • The client sends a request message to the server, and the request message includes information such as the request method, URL, protocol version, and request header.
  • After receiving the request message, the server generates a server response message according to the URL of the request message and corresponding processing logic, and sends it to the client.
  • The response message contains information such as the protocol version, status code, response header, and response body.
  • After the client receives the response message, it will process it according to its own processing method. For example, if it is a web page, the client will parse the HTML code in the response body and render the web page.
  • If it is necessary to continue communicating with the server, the client can initiate a new request and repeat the above steps.

Moreover, in the HTTP protocol, there is no persistent connection between the client and the server, and each request needs to re-establish a connection with the server.

And because HTTP is a stateless protocol, that is to say, the server does not maintain the state information of the client. So there is the emergence of Cookie and Session. And Cookie and Session are used to maintain state.

When it comes to status, we think of status codes again, so what are the status codes of HTTP?

That's great, I immediately thought of the status codes 200, 404, and 500, so let's take a look at how many HTTP status codes there are.

HTTP status code

I have to say, there are quite a lot. If you don’t read it, you don’t know it.

1xx (informational status codes)

  • 100 Continue
  • 101 Switching Protocols
  • 102 Processing

2xx (success status code)

  • 200 OK
  • 201 Created
  • 202 Accepted

204 No Content

  • 207 Multi-Status

3xx (redirection status code)

  • 301 Moved Permanently
  • 302 found
  • 303 See Other
  • 304 Not Modified
  • 307 Temporary Redirect

4xx (client error status code)

  • 400 Bad Request
  • 401 Unauthorized
  • 403 Forbidden
  • 404 Not Found
  • 405 Method Not Allowable
  • 408 Request Time-Out

5xx (server error status code)

  • 500 Internal Server Error
  • 501 Not Implemented
  • 502 Bad Gateway
  • 503 Service Unavailable

Now that everyone understands HTTP, it must lead to HTTPS. Why? Because have you ever encountered one in the development process, some page access addresses are HTTP and some pages are HTTPS, so what is the difference and connection between HTTP and HTTPS?

HTTPS

HTTPS: It is an HTTP channel with security as its goal. In layman's terms, it is a secure version of HTTP

Why is it called HTTPS, the meaning of S, SSL: encryption, adding SSL layer under HTTP

So what's the point of adding an SSL layer?

Because the HTTP request information is transmitted in plain text, it is easy to be stolen. HTTP will not verify the other party's information, and there is a risk of being impersonated. The integrity of the data is not verified, and it is easy to be tampered by the middleman, so SSL is added to ensure security.

SSL operation steps:

  • Verify server side
  • Allow client and server to choose encryption algorithm and cipher, make sure both sides support
  • authenticate client
  • Use public key cryptography to generate shared encrypted data
  • Create an encrypted SSL connection
  • Pass the HTTP request over the SSL connection

**The difference between HTTP and HTTPS

  • The https protocol requires ca to apply for a certificate, and generally there are few free certificates, so a certain fee is required]
  • http is the hypertext transfer protocol, information is transmitted in plain text, https is a secure SSL encrypted transfer protocol
  • http and https use completely different connection methods, and the ports used are also different. The former is port 80 and the latter is port 443
  • The http connection is very simple and stateless; the https protocol is a network protocol constructed by the SSL + HTTP protocol that can perform encrypted transmission and identity authentication, and is safer than the http protocol.
  • In the OSI model, HTTP works at the application layer, while HTTPS works at the transport layer.

Do you know about HTTP?