Review the knowledge

Status code

100-200 indicates requests that continue to be processed, such as protocol upgrades, the most common of which is WebSocket 101.

Between 200 and 300 is success.

Redirection between 300 and 400

The request from 400 to 500 is incorrect

More than 500 are server problems

For example, the first time we visit the gold mining page, the response code is 200 OK, which means no problem.

The next time we visit the nuggets page, the response code is 304 Not Modified, meaning that the page is cached and does Not need to request the resource again, it actually gets the page resource from the cache.

When we put the request parameters after the URL? Aaa =1&bbb=2, re-send the request because the URL has changed, and return the status code 200.

You can also see what parameters you send through the URL:

What is this Network page mainly about

There are three main parameters: Request Method, Request Headers, and the send/Request parameters we just saw.

The request parameters are the get method, which I just append to the URL, and the post method, the PUT method, which is usually put in the body.

These are the three things that usually go wrong.

The course will focus on the application layer, how HTTP works, and mostly on using Node.

Node is not yet involved, so a bit of expertise is in advance:

HTTP Protocol Analysis

Note here that the request header and the request body need to be separated by a line.

Request method

In addition to the most common get and POST request methods, there are:

Method explain
GET Requests a representation of a specified resource. Requests using GET should only be used to GET data
POST Used to commit entities to a specified resource, often resulting in state changes or side effects on the server
PUT Replace all current representations of the target resource with the request payload
DELETE Deletes the specified resource
HEAD Request a response that is identical to the response of the GET request, but without the response body
CONNECT Establishes a tunnel to the server identified by the target resource
OPTIONS Communication options used to describe the target resource
TRACE Perform a message loopback test along the path to the target resource
PATCH Used to apply partial modifications to a resource.

From the characteristics of the re-division

  • Safe
    • Methods that do not modify the server’s data
      • GET HEAD OPTIONS
  • Idempotent
    • The effect of the same request being executed once versus several times in a row isThe sameSo is the state of the serverThe sameAll safe methods are Idempotent
      • GET HEAD OPTIONS PUT DELETE

So how do we understand idempotent?

For example, if a set method is idempotent, if a method changes 1 to 2, the result will be 2 no matter how many times it is executed, so it is idempotent, but add is not idempotent, because executing once and executing many times is not the same.

Give an example of practical scenarios, such as pay this operation must be idempotent, if I paid the money, the results because the network is bad, the background has been performed, but the front desk didn’t get the corresponding feedback, the user may click payment operation again, if not be idempotent, then the second click payment is going to perform a operation, The result was a double deduction, which was clearly unreasonable. Therefore, idempotent should be guaranteed so that the result of repeated payment operation for this order is the same (only deduct money once).

Request header

Common request headers explain
Accept Receive Type, indicating the MIME Type supported by the browser (content-type returned by the benchmarking server)
Content-Type The type of entity content the client sends
Cache-Control Specify the caching mechanism followed by requests and responses, such as no-cache
If-Modified-Since Last-modified matches the server to see if the file has changed to within 1s
Expires Cache control does not request during this time, directly using cache, server time
Max-age Represents the number of seconds that the resource is cached locally
If-None-Match ETag of the server to match whether the file contents have changed (very accurate)
Cookie Have the cookies andThe same domainIt will be automatically attached when accessing
Referer The source URL of this page (applies to all types of requests and will be exact to the detailed page address, which is often used by CSRF interceptors)
Origin Where does the original request originate from (only down to port) and Origin respect privacy more than Referer
User-Agent Some necessary information about the user client, such as the UA header