Network Protocol Related Interview Questions - HTTP Protocol Related Interview Questions

Introduction to the HTTP protocol:

Some basic concepts:

  • Protocol: refers to the regulations or rules that must be complied with in communication between two computers in a computer communication network.
  • HTTP Protocol: The Hypertext Transfer Protocol (HTTP) is a communication protocol that allows Hypertext Markup Language (HTML) documents to be transmitted from a Web server to a client browser. See a picture below:

The difference between URI and URL:
URI: is a uniform resource identifier, a uniform resource identifier, used to uniquely identify a resource. It is mainly composed of three parts:

  • A naming mechanism for accessing resources.
  • The hostname where the resource is stored.
  • The name of the resource itself, represented by the path, with emphasis on the resource.

For example: file://a:1234/b/c/d.txt, where file:// represents the naming mechanism for accessing resources; a:1234 represents the host name for storing resources; b/c/d.txt represents The path to the resource itself.

 

URL: is a uniform resource locator, a uniform resource locator, it is a specific URI, a URL can be used to identify a resource, and it also indicates how to locate the resource.

It is mainly composed of the following three parts:

  • Protocol [such as http or httpps protocol].
  • The host ip address where the resource exists.
  • The specific address of the host resource.

So the URL is a specific URI, it emphasizes the use of the path, and the URI emphasizes the resource.

Features of the HTTP protocol:

  • Simple and fast.
  • not connected. It is automatically disconnected on every request.
  • no status. This protocol has no memory of previous data.

request / reponse:

Open the browser, enter the URL in the address bar, and then we see the web page, what is the principle?

The simple principle is: when the URL is entered, the browser will send a request request to the web server, and the web server will process it accordingly after receiving the request, and then send the response to the browser, and then the browser will parse the response. html document, so that we can see our web page, and it is possible that the request is through a proxy server [it is a transit station, which can improve the access speed, because most proxy servers have a caching function. If you access the address first, use the cache. Finally, go to the web server] and finally reach the web server.

What are the header information of request and response that we need to pay attention to during the interview? Here, charles is used to intercept the request to view:

request:

The next two headers are easier to ignore but important, as follows:

It usually needs to be used in conjunction with the ETag in the request header in the response. Its working principle is: tell the response that the ETag can be added. If the request is made again, the value of the ETag in the If-No-Match will be added to the request header. , at this time, the server can verify that the ETag value has changed. If there is no change, it will return a 304 status code to the client to tell the client that the local cache file can be used, which greatly improves the performance of the client. .

It sends the last modification time of the cached page to the server, and the server will compare it with the last modification time of the actual file on the server according to this time. If it is consistent, it will return 304 to the client, if it is inconsistent, it will return 200 and the latest The content is sent to the client.

Looking at the entire request header, the Referer and If-No-Match request headers are often asked in interviews , so pay attention here.

 

response:

 

 

The last proxy connection ringing is very important. keep-alive means that when the client accesses the http TCP connection of the server, it will not be closed. If the client accesses again, it will continue to use the recommended TCP connection and not again. establish connection.

The more confusing knowledge points in the HTTP protocol:

The difference between http1.1/http1.0:

  • The background of http1.0 The
    HyperText Transfer Protocol (HyperText Transfer Protocol) is accompanied by the birth of computer networks and browsers, and HTTP1.0 also follows. It is located in the application layer of the computer network and is above the TCP protocol.
  • The optimized bandwidth made by http1.0
    : It has been solved at this stage.
    Delay: 1. Browser blocking: The browser can only have 4 connections at the same time for the same domain name.
    Latency: 2. DNS query: The browser needs to know the IP of the target server in order to establish a connection.
    Delay: 3. Establish connection: three-way handshake. Since Http is based on Tcp~
  • The specific difference between http1.1/http1.0
    1. Cache processing: In the http1.0 era, the cache mainly used the If-Modified-Since of the request header as the standard of the cache strategy, and in http1.1 introduced more Cache strategy, such as If-None-Match.
    2. Bandwidth optimization and use of network connections: There are some phenomena of wasting bandwidth in http1.0. For example, the client requesting the server only needs a small part of the data, but the server will return the entire data at the same time. It supports the function of resuming the upload, and a range request header was introduced in the request header in http1.1, which allows only a certain range of data to be requested.
    3. Host header processing: In http1.0, a host only corresponds to a unique IP address, because the request header does not pass the host name, and with the development of virtual hosts, a physical machine can have multiple Virtual host and share an IP address. In http1.1, both request and response have host header messages. If there is none, a 400 error will be reported.
    4. Long connection [This is the biggest difference~] : In http1.0, each request needs to create a connection, while in http1.1, keep-alive long connection is supported by default, and the performance is greatly improved.
  • Problems of http1.1/http1.0
    1. When Http1.X transmits data, it needs to re-establish the connection every time, which undoubtedly increases a lot of delay time. [referring to http1.0, and replacing it with http1.1 can solve this problem]
    2. When Http1.X transmits data, all the transmitted data is in plain text, and neither the client nor the server can verify the identity of the other party [https can be used] Solve this problem]
    3. When Http1.X is used, the content carried in the header is too large, which increases the transmission cost in certain programs.
    4. Although keep-alive is supported in Http1.X to make up for the delay caused by multiple connection creation, the use of keep-alive will also bring a lot of performance pressure to the server.

The difference between get/post methods:

  • Submitted data: Get data will be reflected in the URL when submitted, and post will generally be in the body when submitted.
  • Is there a limit to the size of the submitted data: there is a size limit for the get method, but there is no limit for the post method because it is in the body.
  • Get the value of the variable: The get method is obtained through Request.QueryString, and the post method is obtained through Request.From.
  • Security issues: The get method is definitely not very secure, because the data is carried in the URL, while the post is safer.

The difference between cookies and sessions:

cookie:

  • What is a cookie?
    Cookie technology is a client-side solution. A cookie is special information sent by the server to the client. These information are stored in the client in the form of text files, and then the client will bring it every time it sends a request to the server. these special information. The cookie setting is mainly divided into the following steps:

    The introduction of its mechanism solves the problem of Http being stateless.

  • working principle:

     It is stored on the client side.

session:

  • What is a session?
    Session is another mechanism for recording client state, the difference is that cookies are stored in the client browser, while sessions are stored on the server. When the client browser accesses the server, the server records the client information on the server in some form.
  • The working principle of session:
    1. The first step is of course to create a session: create it when the server is running.
    2. When a session is created, the server will generate a unique session id for the session.
    3. After the session is created, you can call session-related methods to add content to the session.
    4. When the client sends the request again, it will bring the session id. After the server accepts the request, it will find the corresponding session according to the session id.

the difference:

  • The storage location is different: sessions are stored on the server side, while cookies are stored on the client side.
  • The difference in access methods: sessions can store any data type, while cookies can only store strings.
  • Security (privacy policy) is different: sessions are safe, cookies are not.
  • Difference in validity period: session validity period is shorter, while cookies can be longer.
  • The pressure on the server is different: the session puts more pressure on the server, while the cookies are stored on the client side and do not put pressure on the server at all.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325116234&siteId=291194637