Before the summary of a TCP/HTTP interview questions, this time also added some other computer network interview questions, for the convenience of reading sorted together, and according to the frequency of interview questions made notes (the higher the number of stars, the higher the frequency of interview questions), if there is help to you, you can collect the likes and support oh. >

Search the public account zhang on wechat, reply to the interview manual, and get the PDF version of this document and more interview materials.

Recommended reading:

  • Understand all basic Java knowledge questions

  • Understand all the Java collection interview questions

    What are network protocols and why are they layered *

    Network protocols are some agreed rules that computers follow in the process of communication.

    Causes of network layering:

    • It is easy to implement and maintain because the layers are independent and not affected from one layer to another.
    • Conducive to the formulation of standardization

    Layer protocols and functions of computer networks

    Computer network system can be roughly divided into the following three, seven-layer model, five-layer model and TCP/IP four-layer model, general interview can fluently answer the five-layer model can, presentation layer and session layer was asked not much.

    • The application layer

      The task of the application layer is to achieve specific network functions through the interaction between application processes. Common application layer protocols include domain name system (DNS) and HTTP.

    • The presentation layer

      The main function of presentation layer is data representation, security and compression. Ensures that information sent by the application layer of one system can be read by the application layer of another system.

    • The session layer

      The main function of the session layer is to establish communication links, keep the unimpeded communication links in the session process, synchronize the dialogue between two nodes, determine whether the communication is interrupted and decide where to resend the communication when it is interrupted.

    • The transport layer

      The transport layer is responsible for providing data transfer services for communication between two host processes. The protocols at the transport layer are TCP and UDP.

    • The network layer

      The main function of the network layer is to select suitable routing and switching nodes between networks to ensure timely data delivery. Common protocols are IP.

    • Data link layer

      The function of data link layer is to establish data link between adjacent nodes on the basis of bitstream service provided by physical layer, provide error-free transmission of data Frame on channel through error control, and carry out action series on each circuit. Common protocols include SDLC, HDLC and PPP.

    • The physical layer

      The main function of the physical layer is to realize the transparent transmission of bitstreams between adjacent computer nodes and shield the differences between specific transmission media and physical devices as far as possible.

    The difference between urIs and urls *

    • Uniform Resource Identifier (URI) : A Uniform Resource Identifier (URI) uniquely identifies a Resource.
    • Uniform Resource Location (URL) : Uniform Resource Locator (URL), which provides the path of resources.

    The classic analogy is that a URI is like an ID card that uniquely identifies a person, while a URL is more like an address where you can find the person.

    DNS workflow * * *

    Definition of DNS: The full name of DNS is domain Name System. DNS is a distributed database that maps domain names to IP addresses on the Internet, making it easier for users to access the Internet without having to remember IP addresses that can be read directly by machines. When people visit Baidu, for example, they are more likely to visit www.baidu.com than 112.80.248.74, because the almost random IP address is too hard to remember. All DNS has to do is resolve www.baidu.com to 112.80.248.74.

    Does DNS work in a cluster or a single point? Why?

    The answer is clustered, and it’s easy to think of a solution that uses just one DNS server, with all the mapping of domain names and IP addresses. While this approach seems simple, the downside is obvious. If the single DNS server fails, it’s all over, and the Internet almost collapses. In order to avoid this problem, DNS system adopts the distributed hierarchical data database mode, and the caching mechanism can also solve this problem.

    DNS workflow

    The host queries the local DNS server recursively, while the local DNS server queries the root domain name iteratively.

    If the local DNS server does not know the IP address of the domain name, the local domain name continues to send query packets to the root domain name, rather than notifies the host to send query packets to the root domain name. Iterative query: After the local DNS server sends a query request packet to the root domain name, the root domain name notifies the local DNS server to send a query request packet to the top-level domain name.

    To put it simply, recursive query is, Xiao Ming asked Xiao Hong a question, Xiao Hong did not know, but xiao Hong is a warm-hearted, xiao Hong went to ask Xiao Wang, Xiao Wang told xiao Hong the answer, xiao Hong went to tell the answer to Xiao Ming. Iterative query is, Xiao Ming asked Xiao Hong a question, Xiao Hong did not know, and then Xiao Hong asked Xiao Ming to ask Xiao Wang, Xiao Ming asked Xiao Wang, Xiao Wang told xiao Ming the answer.

    1. Enter www.baidu.com in the address box of the browser. The operating system checks whether the domain name is mapped to the local hosts file. If yes, the OPERATING system invokes the IP address mapping to resolve the domain name.
    2. If no, query the local DNS parser cache. If yes, the address is resolved.
    3. If the local DNS server does not exist in the cache, search for the local DNS server. If yes, complete the parsing.
    4. If not, the local server sends a query request to the root DNS server. The root DNS server tells the local DNS server which TOP-LEVEL DNS server to query.
    5. The local DNS server sends a query request to the TOP-LEVEL domain name server, and the TOP-LEVEL domain name server tells the local DNS server which domain name server to search for.
    6. The local DNS server sends a query request to the domain name server, and the domain name server informs the local DNS server of the IP address corresponding to www.baidu.com.
    7. The local DNS server tells the host the IP address of www.baidu.com.

    Do you know ARP? * *

    ARP is a network-layer protocol that translates IP addresses into MAC addresses. Each host or router has an ARP cache table, which contains IP addresses and their CORRESPONDING MAC addresses. Let’s look at what IP addresses and MAC addresses are.

    • IP address: An IP address is an Internet protocol address. An IP address is a unified address format provided by the IP protocol. It allocates a logical address to each network and each host on the Internet to mask physical address differences.
    • MAC address: A MAC address is also called a physical address. It is written into the hardware during production by the network device manufacturer and cannot be changed. The MAC address of each Ethernet device is unique.

    During data transmission, data is first transferred from the upper layer to the lower layer and then transmitted on the communication link. As shown in the following figure, TCP packets are encapsulated as IP datagrams at the network layer and MAC frames at the data link layer, and then transmitted on the communication link. IP addresses are used at the network layer and MAC addresses are used at the data link layer. The source and destination ADDRESSES of MAC frames are both MAC addresses. The host or router on the communication link receives the MAC frame based on the MAC address at the beginning of the MAC frame. In addition, the IP address cannot be seen at the data link layer. The source IP address and destination IP address can be found in the header of the IP packet only when the header and tail of the MAC frame are removed when the data is transmitted to the network layer.

    The network layer implements communication between hosts, while the link layer implements communication between links. Therefore, the following figure shows that during data transmission, the source address (IP1) and destination address (IP2) of IP datagrams remain unchanged, while the MAC address (hardware address) changes with the change of links.

    ARP work flow (interview ask ARP protocol mainly said this can be) :

    1. If host A wants to send an IP time report to host B on the LAN, host A checks the ARP cache table for an IP address and its MAC address. If yes, host A writes the MAC address to the head of A MAC frame and sends the MAC frame to host B over the LAN.
    2. If host A does not have host B’s IP address and MAC address in the ARP cache table, host A broadcasts and sends an ARP request packet on the LAN. All hosts on the LAN receive the ARP request packet.
    3. When host B sees that host A has its own IP address in the ARP request packet sent by host A, host B sends A response packet with its own MAC address in unicast mode.
    4. After receiving the ARP response packet from host B, host A writes the IP address of host B and its MAC address into the ARP cache table.
    5. If host A and host B are not on the same LAN, they cannot communicate with each other even if they know the MAC address of host B. They must be forwarded to host B’s LAN through A router so that host B can find host B using the MAC address of host B. If hosts A and B can communicate with each other, the ARP cache of host A contains the IP address of host B and the MAC address of the next-hop router on the communication link, rather than the IP address and MAC address of host B. In the figure above, the source and destination IP addresses remain the same, while the MAC address varies from link to link.
    6. If host A and host B are not on the same LAN, refer to host H1 and host H2 in the preceding figure. In this case, host H1 broadcasts to find the MAC address of router R1, and then R1 broadcasts to find the MAC address of router R2. Finally, R2 broadcasts to find the MAC address of host H2 to establish A communication link.

    Why use a MAC address when you have an IP address? * *

    To put it simply, the IP address and MAC address are commonly used to identify a computer on the network. However, the IP address of a computer can be changed by users and it is relatively difficult to manage, while the MAC address cannot be changed. Therefore, THE IP address and MAC address are generally used together. How to combine them is explained in the ARP protocol above.

    Can you just use a MAC address instead of an IP address? In fact, it is not possible, because in the earliest is MAC address first appeared, and IP address was not used at that time, only MAC address, later with more and more devices in the network, the whole routing process is more and more complex, then appeared the concept of subnet. For packets whose destination IP addresses reside on other subnets, the route only needs to send the packets to the subnets. This process is referred to as THE ARP protocol.

    So why use an IP address? Because the IP address is associated with regional, for the protection of the equipment in the same subnet an IP address prefix is same, so the router by IP address prefix to know where the equipment is online, and only use the MAC address, the router will need to remember each MAC address in which subnet, this need a router to have great storage space, It can’t be done.

    An IP address can be used as an address, and a MAC address can be used as the recipient. Both are indispensable in a communication process.

    Talk about the ping process * *

    Ping is an important application of ICMP(Internet Control Message Protocol), which is a network layer protocol. Ping tests the connectivity between two hosts.

    How ping works:

    1. Multiple ICMP echo request packets are sent to the destination host
    2. The round-trip time and packet loss rate of packets are estimated based on the return packet time and successful response times of the destination host.

    The difference between a router and a switch? *

    The hierarchy of the owning network model function
    The router The network layer Identify IP addresses and forward packets based on IP addresses, maintain data tables and select the best path based on the data tables
    switches Data link library layer Identify MAC addresses and forward data frames based on MAC addresses

    What is the difference between TCP and UDP

    Connection-oriented or not reliability Transfer form Transmission efficiency Consume resources Application scenarios The first byte
    TCP connection-oriented reliable Byte stream slow more File/mail transfer 20 ~ 60
    UDP There is no connection unreliable Data packet segment fast less Video/voice transmission 8

    Sometimes the interview question is what does the TCP header contain

    • TCP header (image from network) :

      The first 20 bytes are fixed, followed by 4N additional options as needed, so the minimum length of the TCP header is 20 bytes.

    • UDP header (image from network) :

      The UDP header contains only 8 bytes, two bytes each for the source port number, destination port number, length, and checksum.

    How does TCP guarantee reliable transmission

    The main methods include checksum, serial number, timeout retransmission, flow control and congestion avoidance.

    • Checksum: The sending and receiving end calculates the checksum of data respectively. If the checksum is inconsistent with the checksum, an error occurs during data transmission. TCP discards and does not acknowledge this packet segment.

    • Sequence number: TCP numbers each sent byte. After receiving the data, the TCP sends an ACK packet to the sender. The ACK packet contains an ACK number that tells the sender that the next data to be sent starts from the number. If the sender sends the same data, the receiver can determine the sequence number and discard the data. if

    • Timeout retransmission: The purpose of the sequence number is described above, but if the sender does not receive an ACK with an acknowledgment sequence number within a certain period of time (which can be specified by setting a retransmission timer) after sending the data, the sender will resend the data.

      There are two cases in which the sender does not receive an ACK. If the packet sent by the sender is lost, the receiver will send an ACK to the sender immediately after receiving the re-sent packet from the sender. If the ACK returned to the sender is lost after receiving the packet sent by the sender, after the sender retransmits the packet, the receiver directly discards the packet sent by the sender and sends an ACK response packet again.

      If no acknowledgement from the receiver is received after the data is retransmitted, the data is sent again. At this point, the waiting time for a confirmation response increases exponentially by a factor of two or four until the connection is finally closed.

    • Flow control: If the data sent by the sender is too fast for the receiver to receive, packet loss will occur. To solve this problem, TCP protocol makes use of sliding Windows for flow control. There is a 16-bit field size window in the TCP header. The size of the window is the remaining size of the buffer for receiving data. When receiving an ACK packet, the receiver fills its window size in the ACK packet. The sender controls the sending speed according to the window size in the ACK packet. If the window size is zero, the sender stops sending data.

    • Congestion control: If the network is congested, packet loss will occur. In this case, the sender will retransmit the lost packets, and the network congestion will become more serious. Therefore, when the network is congested, you should control the data sent by the sender to reduce the network congestion. Congestion control consists of four parts: slow start, congestion avoidance, fast retransmission, and fast recovery, as shown in the following figure (from the network).

    The sender will maintain a congestion window state variables, it and the traffic control of the sliding window is different, the sliding window is set according to the receiver data buffer size, and the congestion window is set according to the network congestion situation dynamic, in general the sender real send window for sliding window and the lowest value of the congestion window.

    1. Slow start: In order to avoid network congestion caused by sending a large amount of data at the beginning, the CWND is initialized to 1. After receiving an ACK, the CWND is 2 in the next transmission round, and so on in an exponential form.

    2. Congestion avoidance: Because the number of CWND increases exponentially at the slow start, a slow start threshold ssTHRESH is set to prevent network congestion due to the large number of CWND. When CWND >= SSTHRESH enters the congestion avoidance stage, CWND increases by 1 for each transmission turn. When a timeout occurs, the threshold SSTHRESH becomes half of the value of CWND when timeout occurs. CWND is reset to 1, as shown in the figure above. After the timeout occurs in round 12, CWND becomes 1 and SSTHRESH becomes 12.

    3. Fast retransmission: If timeout or congestion occurs on the network, adjust according to the slow start and congestion avoidance algorithms. However, if only one packet segment is lost, as shown in the following figure (the picture is from the network), the fast retransmission algorithm is used.

    As can be seen from the figure above, the receiver has correctly received M1 and M2, while M3 is lost. Since M3 is not received, the receiver will not confirm when it receives M5, M6 and M7, that is, it will not send ACK. In this case, according to the function of serial number in ensuring TCP reliability transmission mentioned above, the receiver will not receive M5, M6, and M7 at this time. The receiver can not receive anything, because the sender does not receive M3 confirmation message for a long time, and will retransmit M3. In addition, the receiver can repeatedly send M2 acknowledgement packets. In this way, the sender will continue to send M3 packets even if it does not receive M3 acknowledgement packets for a long time.

    However, according to the fast retransmission algorithm, in this case, it is required to quickly send M2 acknowledgement packets to the sender. After receiving three M2 acknowledgement packets, the sender can directly retransmit M3 without waiting for the time set by the retransmission timer, which is fast retransmission. (This sentence is enough for the interview.)

    1. Fast recovery: As can be seen from circle 4 above, when the sender receives three duplicate acks, fast retransmission and fast recovery are performed. Fast recovery means that SSTHRESH is set to half the number of CWND when fast retransmission occurs, and instead of CWND being set to 1, CWND is set to threshold SSTHRESH and the congestion avoidance phase begins.

    TCP three-way handshake and four-way wave * * *

    Will the questions

    Before introducing the three-way handshake and the four-way wave, let’s look at some common TCP header fields.

    • Serial number: SEQ, which is 32 bits, identifies the byte stream sent from sender to receiver.
    • Confirmation number: ACK. The field is valid only when the ACK flag bit is 1. Ack = SEq +1.
    • Mark:
      • SYN: Initiates a new connection.
      • FIN: Releases a connection.
      • ACK: Confirms that the serial number is valid.

    Three-way handshake

    The essence of the three-way handshake is to confirm that the sender and the receiver have the ability to send and receive information. In addition to smoothly describing the three-way handshake process and the function of the field meanings, the state of the receiver and the sender during each handshake should be remembered. This is easy to ignore.

    Let’s take a look at the classic figure (the figure is from the network). The three states are CLOSED, SYN-sent, and ESTABLISHED on the sender, and the four states are CLOSED, LISTEN, SYN-rcvd, and ESTABLISHED on the receiver.

    Assume that the sending end is the client and the receiving end is the server. Both client and server states are CLOSE at the beginning.

    • First handshake: The client initiates a connection request to the server. The client randomly generates a starting sequence number X. The field sent by the client to the server contains the flag bit SYN=1 and the sequence number seq=100. The state of the client is CLOSE before the first handshake and syn-sent after the first handshake. The status of the server is LISTEN
    • Second handshake: After receiving a packet from the client, the server randomly generates a start sequence number Y and sends a packet to the client containing SYN=1, ACK=1, SEQUENCE number SEq = Y, and ACK= X +1. Before the second handshake, the state of the server is LISTEN. After the second handshake, the state of the server is SYN-rcVD. In this case, the state of the client is SYN-sent. (SYN=1 indicates that a connection is to be established with the client, ACK=1 indicates that the sequence number is valid)
    • Third handshake: After receiving a packet from the server, the client sends another packet to the server. The packet contains the ACK bit (ACK=1), sequence number (SEq = X +1), and confirmation number (ACK= Y +1). The state of the client is SYN-sent before the third handshake, and the state of the client and server is ESTABLISHED after the third handshake.

    Note that during the first handshake, the client sends a connection establishment packet to the server, which has a sequence number. However, in the third handshake, the client also sends a packet to the server, but the sequence number is not captured this time. Therefore, after the connection is established, the serial number of the first data sent from the client to the server is X +1.

    Four times to wave

    Similar to the three-way handshake, let’s take a look at a very classic picture. The client has five states ESTABLISHED, fin-WaIT-1, FIN-WaIT-2, time-wait, and CLOSED during the four-way handshake. The server can be in the ESTABLISHED, close-wait, last-ack, and CLOSED states. It is best to remember the state of the server and client at each wave. Assume that the client initiates the first disconnection request

    • First wave: After sending data to the server, the client sends a connection release packet to the server. The packet contains FIN flag bit 1 and SEQ sequence number U. In this case, the client can only receive data, but cannot send data to the server.
    • Second wave: After receiving the connection release packet from the client, the server sends an acknowledgement packet containing ACK=1, SEQ = V, and ACK= U +1. In this case, the connection between the client and the server is released. The client cannot send data to the server, and the server cannot send data to the client. However, the one-way connection between the server and the client can still transfer data normally.
    • Third wave: After sending data, the server sends a connection release packet to the client. The packet contains FIN bit 1, ACK bit 1, sequence number SEq = W, and ACK number U +1.
    • Fourth wave: After receiving the connection release request from the server, the client sends an acknowledgement packet to the server containing ACK=1, SEQ = U +1, and ACK= W +1.

    Why are TCP connections made 3 times? Is twice ok?

    No. Consider the following two aspects (assuming that the client initiates the connection request first) :

    1. TCP connection to assume that only requires two shake hands, so if the second handshake, the server returned to the client confirmation message lost, don’t think the server is the client side and his connection is established, and the server is thought have established a connection, and the client to server and may have already begun to send data to the client, but the client will not receive these data, A waste of resources. In a three-way handshake, data will not be sent before the connection is fully established.
    2. If the server receives an invalid connection request packet from the client, it sends a confirmation packet to the client to establish a TCP connection. But because the client does not need to send data to the server, the TCP connection is meaningless and wastes resources.

    Why are TCP connections made 3 times and closed 4 times?

    Because of the need to ensure that both sides of communication can notify the other party released connection, assuming that the end of the service to send the data to the server to send release the connection request, when the end of the service does not know that the server is sending data, so the broken is the end of the service to the service side one-way connection, the server returned to the client after confirmation message, the server can continue one-way send data to the client. After sending data, the server sends a request to release the TCP connection to the client. The client sends an acknowledgement packet to close the TCP connection. Therefore, to disconnect a TCP connection, the client and server need to notify each other and receive confirmation packets respectively, which requires a total of four times.

    What is the difference between TIME_WAIT and CLOSE_WAIT?

    The default client initiates the disconnection request first

    • As shown in the figure above, CLOSE_WAIT is closed passively. When the client sends a FIN packet, the server returns an ACK packet to initiate CLOSE_WAIT.
    • TIME_WAIT is an active shutdown. When the fourth wave is complete, the client enters the TIME_WAIT state.

    Why does the client wait 2MSL to release the TCP connection after sending the fourth wave acknowledgement packet?

    MSL stands for the maximum lifetime of a message, which can be considered in two ways:

    1. After the client sends the packets in the fourth wave and passes through 2MSL, all the packets in the current TCP connection disappear and do not appear in the next TCP connection.
    2. Consider packet loss. If the packet sent with the fourth wave is lost during transmission, the server resends the packet with the third wave if it does not receive the ACK packet. If the client shuts down after sending the fourth wave acknowledgement packet and the packet is lost, the server cannot be shut down.

    What if the connection has been established, but the client suddenly fails?

    If a TCP connection is established and the client suddenly fails during communication, the server will not wait for a while and then close the connection. TCP has a keepalive mechanism, which is mainly used on the server to detect the status of the client with a TCP connection to prevent the client from crashing or the network is unreachable, but the server keeps the TCP connection. It takes up a lot of resources on the server side (because there is a limit to the total number of TCP links that can be created on Linux systems).

    Keepalive mechanism Principle: Set the keepIdle time of the TCP keepalive mechanism. When the TCP connection expires and no data is exchanged, keepalive probe packets are sent. Set the keepInterval for sending keepalive probe packets. Set the keepCount for sending keepCount of keepalive probe packets. If no response is received from the client after keepCount attempts, the server closes the TCP connection with the client.

    For details, see this blog post about exceptions during TCP communication.

    The difference between HTTP and HTTPS * * *

    HTTP HTTPS
    port 80 443
    security No encryption, poor security With encryption mechanism, high security
    Resource consumption less More resources are consumed due to encryption processing
    Whether certificate is required Don’t need Need to be
    agreement It runs on top of TCP Runs on TOP of SSL, which runs on top of TCP

    What is symmetric and asymmetric encryption * *

    • Symmetric encryption

      Symmetric encryption refers to the use of the same key for encryption and decryption. The advantages of symmetric encryption are high computing speed, but the disadvantages are how to securely transfer the key to the other party. Common symmetric encryption algorithms include DES and AES.

    • Asymmetric encryption

      Asymmetric encryption refers to encryption and decryption using different keys, a public public key and a private private key. Only the private key can decrypt the information encrypted by the public key, and only the public key can decrypt the information encrypted by the private key. Advantages solve the problems existing in symmetric encryption. The disadvantage is that the operation speed is slow. Common asymmetric encryption algorithms include RSA, DSA, ECC and so on.

      Asymmetric encryption workflow: USER A generates A pair of non-heaped keys and discloses the public key to everyone. User B gets the public key of USER A and encrypts the information using the public key of user A and sends the encrypted information to user A. Only user A’s private key can decrypt the encrypted information. In this way, USER B can encrypt its own public key and send it to USER A. The two parties establish communication. The public key of the other party can encrypt the information to be sent, and the receiver can decrypt the information with its own private key.

    HTTPS encryption process * * *

    The advantages and disadvantages of symmetric encryption and asymmetric encryption have been introduced. HTTPS is a hybrid encryption algorithm that combines the two encryption algorithms. The specific approach is to use asymmetric encryption to transfer symmetric keys to ensure security and use symmetric encryption to ensure communication efficiency.

    Simplified workflow: The server generates a pair of asymmetric keys and sends the public key to the client. The client generates a symmetric key, encrypts it with the public key sent by the server, and sends the encrypted key to the server. After receiving the packet, the server decrypts it with the private key to obtain the symmetric key sent by the client. The communication parties can communicate efficiently with symmetric keys.

    However, there is a big problem when you think about it. How can the client determine that the public key received is from the server in the first place and not someone else impersonating it?

    The server will apply for a certificate from an authority to prove its identity, and then send the certificate (containing the public key) to the client. After receiving the certificate, the client can verify the identity of the server and obtain the public key to proceed with the next operation.

    HTTPS encryption process:

    1. The client sends the first handshake request to the server to inform the server of the specified SSL version, encryption algorithm, and key length supported by the client.
    2. The server sends its public key to the DIGITAL certificate Authority, which uses its private key to digitally sign the server’s public key and issues a public key certificate to the server.
    3. The server sends the certificate to the client.
    4. The customer service uses the public key of the DIGITAL certification Authority to verify the digital signature on the public key certificate and verify the authenticity of the server public key.
    5. The client uses the public key of the server to encrypt the symmetric key generated by itself and sends it to the server.
    6. The server uses the private key to decrypt the information and obtain the symmetric key sent by the client.
    7. The communication parties can use symmetric keys to encrypt and decrypt messages.

    One problem with this process is where the client gets the public key of the digital certificate authority. In fact, many browsers have the public key of the common digital certificate authority built in.

    The flow chart is as follows:

    Common HTTP status code * * *

    This is also a common interview question, just memorize it.

    Status code category
    1XX Informational status code
    2XX Success status code
    3XX Redirection status code
    4XX Client error status code
    5XX Server error status code

    Common HTTP status codes

    1XX

    • 100 Continue: The client can Continue to send requests
    • 101 Switching Protocols: Switching Protocols that a server switches on a client request.

    2XX

    • 200 OK: The request is successful
    • 201 Created: Created, a new resource is successfully requested and Created
    • 202 The request was Accepted, but the processing was not completed.
    • 204 No Content: No Content. The server processed it successfully, but did not return any Content.
    • 205 Reset Content: Resets the Content. The server processes the document successfully and the client resets the document view.
    • 206 Partial Content: Indicates that the client sends a Range request. The response packet should contain Content in the specified Range of content-range

    3XX

    • 301 Moved Permanently: Permanent redirection
    • 302 Found: Temporary redirection
    • 303 See Other: Provides the same functions as 301 but requires the client to use the GET method to obtain resources
    • 304 Not Modified: The requested resource has Not been Modified. When the server returns this status code, no resource is returned.
    • 305 Use Proxy: The requested resource must be accessed through a Proxy
    • 307 Temporary Redirect: Temporary redirection. Similar to 302, get requests are required for redirection.

    4XX

    • 400 Bad Request: The syntax of the client Request is incorrect and the server cannot understand it.
    • 401 Unauthorized: The request to be sent requires authentication information.
    • 403 Forbidden: The server understands user requests but refuses to execute them
    • 404 Not Found: The server could Not find the resource requested by the client.
    • 405 Method Not Allowed: Methods in the client request are prohibited
    • 406 Not Acceptable: The server was unable to complete the request based on the content nature of the client request
    • 408 Request time-out: The server waits too long for the Request sent by the client and times out

    5XX

    • 500 Internal Server Error: The request cannot be completed due to an Internal Server Error
    • 501 Not Implemented: The server did Not support the requested functions and could Not complete the request

    Common HTTP methods * * *

    methods role
    GET Access to resources
    POST Transport entity body
    PUT Upload a file
    DELETE Delete the file
    HEAD Similar to GET, only the header of the packet is returned, but the body of the packet is not returned
    PATCH Modify some resources
    OPTIONS Queries methods supported by the specified URL
    CONNECT A tunnel protocol is required to connect the agent
    TRACE The server returns the communication path to the client

    To facilitate memory, PUT, DELETE, POST, and GET can be interpreted as adding, deleting, modifying, and querying data from the client to the server.

    • PUT: uploads files and adds data to the server
    • DELETE: deletes a file
    • POST: transmits data, submits data to the server, and updates the server data.
    • GET: obtains resources and queries server resources

    GET is different from POST

    • role

      GET is used to GET resources and POST is used to transport entity bodies

    • Parameters of the position

      The parameters of GET are stored in the URL, the parameters of POST are stored in the entity body, and the data in the URL of the request submitted by the GET method is 2048 bytes, and the size of the POST request is not limited.

    • security

      The GET method is less secure than POST because the parameters are placed in the URL

    • idempotence

      The GET method is idempotent, whereas the POST method is not. Here idempotent means that the client makes multiple requests in a row and receives the same result.

    What are the main differences between HTTP 1.0, HTTP 1.1, and HTTP 2.0

    Differences between HTTP 1.0 and HTTP 1.1

    • A long connection

      HTTP 1.1 supports pipelining of long connections and requests. Long connections do not need to be re-established for each request. HTTP 1.0 uses short connections by default. TCP connections need to be re-established for each request, consuming large resources. In pipelined request operations, clients can send new request packets before receiving HTTP response packets. Pipelined request operations that do not support requests can send new request packets only after receiving HTTP response packets.

    • Cache handling

      In HTTP 1.0, if-Modified-since and Expires in headers were mainly used as criteria for cache judgment. HTTP 1.1 introduced Entity Tag, If-unmodified-since, if-match, and more cache headers are available to control the cache strategy.

    • Error status code

      24 error status response codes have been added to HTTP 1.1

    • The HOST domain

      In HTTP 1.0, it was assumed that each server was bound to a unique IP address, so the URL in the request did not pass the hostname. Later, however, there could be multiple virtual machines on a server that share the same IP address, so both request and response messages in HTTP 1.1 should support the Host domain.

    • Bandwidth optimization and network connection usage

      In HTTP 1.0, there was a waste of bandwidth, mainly because the breakpoint continuation function was not supported. The client only needed part of an object, but the server passed the whole object. In HTTP 1.1, request headers introduced the range header field, which allows you to request only a portion of a resource and return a status code of 206.

    New features in HTTP 2.0

    • New binary format: HTTP 1.x parsing is based on text, HTTP 2.0 parsing using binary, easy to implement, better robustness.
    • Multiplexing: Each request has an ID. A connection can have multiple requests. The requests for each connection can be randomly mixed so that the receiver can group the requests into different server requests based on the REQUEST ID.
    • Header compression: In HTTP 1.x, the header carries a large amount of information and needs to be sent again each time. HTTP 2.0 uses encoding to reduce the size of the header, and both communication parties cache a header fields table to avoid repeated transmission of the header.
    • Server push: When a client requests a resource, it sends the related resource to the client, so that the client does not need to make another request.

    Key differences between Session, Cookie and Token * * *

    The HTTP protocol is stateless, that is, the server cannot identify the user. Sessions and cookies can be used for identification.

    • Cookie

      A Cookie is a small block of data stored on the client, which contains user information. When the client sends a request to the server, the server will send a Cookie to the browser of the client, and the client will save the Cookie. The next time the client requests the server again, it will carry the Cookie, and the server will confirm the identity through the Cookie.

    • Session

      The Session is implemented through cookies. Different from cookies, the Session exists on the server. When the client browser accesses the server for the first time, the server creates a sessionid for the browser and stores the sessionid in a Cookie, which is stored in the client browser. For example, when the browser visits a shopping website and puts an illustrated HTTP book into the shopping cart, when the browser visits the server again, the server will fetch the sessionID in the Cookie and obtain the information stored in the session according to the sessionID. Verify that the browser is the user who put the Illustration HTTP in the cart last time.

    • Token

      When the client accesses the server for the first time, the client sends a string generated by the server as a Token to the client browser. The next time the browser accesses the server with the Token, it does not need to verify the user name and password, saving a lot of resources. A lot of people look at this and say, well, isn’t that the same thing as sessionID? In fact, it is not the same, but this article is mainly for the interview, there are many knowledge points, space is limited, a few words can not explain clearly, you can have a look at this article, I think it is very clear. The real difference between cookie, session and Token

      In order to facilitate memory, a table is made for comparison.

      location Take up the space security Application scenarios
      Cookie Client browser small The lower Generally, it stores configuration information
      Session The service side more higher Store important information

    Does it still work if the client disables cookies? *

    Yes, the Session is used to maintain state on the server, and the identity is confirmed by the Session ID, but the Session ID is usually passed through the Cookie. If Cooike is disabled, you can do this by passing the sessionID in the URL.

    The process of entering the URL address in the browser to display the home page * * *

    Interview ultra high frequency of a question, generally can make clear the process can.

    1. The URL entered to the browser is resolved by DNS, and the domain name is converted to an IP address.
    2. The TCP connection is established with the destination server
    3. Sends an HTTP request to the destination server
    4. The server processes the request and returns HTTP packets
    5. The browser parses and renders the page

    Are servlets thread-safe

    Servlets are not thread-safe, and multithreaded reads and writes can cause data synchronization problems.