“Reed” Dragon Boat Festival, “dad” full of gas! Dragon Boat Festival is approaching, Aileen continues to send benefits to everyone. On this idyllic and fun day, let’s take a look at some of the classic HTTP problems that will set you apart from the rest.

Question 1: What process should a web page go through before it can reach users?

In other words: what happens to a page from the time the URL is entered to the time the page is loaded and displayed? That’s how HTTP works. Here’s a picture:

  • 1. Responsibilities of HTTP protocol: generate HTTP request packets corresponding to the target Web server. Please give me the resources on http://hack/account/web page.
  • 2. TCP protocol responsibilities: To facilitate communication, HTTP request packets are divided into packet segments, divided into multiple packet segments according to the serial number, and each packet segment is reliably transmitted to the other party;
  • 3, THE responsibilities of IP protocol: search the address of the other side, transfer side transmission;
  • 4. TCP reassembles the segments received from the peer and reassembles the request packets in the original sequence.
  • 5, HTTP protocol responsibility: web server content request processing, originally wanted to this computer /account/ resources.

Question 2: What are commonly used HTTP status codes and their meanings?

  • 200 (Data sent from OK client is processed normally)
  • 204 (Not Content Normal response, no entity)
  • 206 (Partial Content Range request, returns Partial data, responds to the entity Content specified by content-range)
  • 301 (Moved Permanently redirected Permanently
  • 302 (Found) temporary redirection, the specification requires the _x001D_ method name to remain the same, but will change
  • 303 (See Other) is similar to 302, but the GET method must be used
  • _x0008_ Match (if-match, if-modified-since, if-none_match, if-range, if-unmodified-since)
  • 307 (Temporary Redirect) Request methods should not be changed
  • 400 (Bad Request) The syntax of the Request packet is incorrect
  • 401 (Unauthorized) Requires authentication
  • 403 (Forbidden) The server denies access to corresponding resources
  • 404 (Not Found) Resources could Not be Found on the server
  • 500 (Internal Server Error) The Server is faulty
  • 503 (Service Unavailable) The server is overloaded or is being stopped for maintenance

Question 3: What is the difference between HTTP and HTTPS?

First of all, HTTPS is the Secure Hypertext Transfer Protocol, which uses SSL to encrypt information on the basis of HTTP.

The main differences between HTTP and HTTPS:

  • 1. Difference between HTTPS and HTTPS HTTPS requires you to apply for a certificate from a CA. Generally, a few free certificates need to be paid.
  • 2. HTTP is a hypertext transmission protocol, and information is transmitted in plain text. HTTPS is a secure SSL encryption transmission protocol.
  • 3. HTTP and HTTPS use completely different connection methods and different ports, the former is 80 and the latter is 443.
  • 4. HTTP connections are simple and stateless.
  • 5. HTTPS is a network protocol constructed by SSL and HTTP for encrypted transmission and identity authentication. It is more secure than HTTP.

Q4: Implementing an HTTP server program using Node.js?


var http = require('http');
var server = http.createServer(function (request, response) {
    console.log(request.method + ': ' + request.url);
    response.writeHead(200, {'Content-Type': 'text/html'});
    response.end('

Hello world!

'); }); server.listen(8080); The console. The log (' Server is running at http://192.168.10.204:8080/ ');Copy the code

Code parsing:

1. Import the HTTP module. Create an HTTP server and pass in a callback function. 3. In the callback function: the callback function receives request and Response objects and obtains the METHOD and URL of the HTTP request; 4. Write the HTTP response 200 to response and set content-type: text/ HTML. 5. Finally, write the HTML content of the HTTP response to response; 6, let the server listen on port 8080, you can see in the browser 'Hello world! '.Copy the code

Q5: What is the difference between GET and POST?

  • 1. On the client side, Get submits data through THE URL, and the data can be seen in the URL; In POST mode, data is submitted in HTML headers.
  • 2. A maximum of 1024 bytes of data can be submitted by GET, but there is no such limit for POST.
  • 3. Security issues. As mentioned in Point 1, when you use Get, the parameters are displayed in the address bar, while Post is not. So, if the data is Chinese and non-sensitive, use GET; If the data the user enters is not Chinese characters and contains sensitive data, use POST.
  • 4. Safe and idempotent.

Comments:

  • Safe means that the operation is used to retrieve information, not modify it. Idempotent means that multiple requests to the same URL should return the same result. The full definition is not as strict as it seems.
  • In other words, GET requests should generally have no side effects. Basically, the goal is that when a user opens a link, she can be confident that she hasn’t changed the resource from her point of view.
  • For example, the front page of a news site is constantly updated. Although the second request returns a different batch of news, the operation is still considered safe and idempotent because it always returns the current news. And vice versa.
  • POST requests are not so easy. POST represents a request that might change a resource on the server. Again, in the case of a news site, reader comments to articles should be made via POST requests because the site is different after the comments are submitted.

conclusion

Today first to share here, I hope to help you, I wish you a happy Dragon Boat Festival!