Computer network notes: HTTP about put, get, post, option requests

Common HTTP request methods

  • GET: Obtain data from the server;
  • POST: Submit the entity to the specified resource, usually resulting in modification of the server resource;
  • PUT: upload files, update data;
  • DELETE: delete the object on the server;
  • HEAD: Get the header of the message. Compared with GET, it does not return the body of the message;
  • OPTIONS: Inquire about supported request methods, used for cross-domain requests;
  • CONNECT: It is required to establish a tunnel when communicating with the proxy server, and use the tunnel for TCP communication;
  • TRACE: Echo the request received by the server, mainly for testing or diagnosis.

The difference between GET and POST requests

  • 应用场景: A GET request is an idempotent request. Generally, a Get request is used in scenarios that do not affect server resources, such as requesting a webpage resource. Post is not an idempotent request, and is generally used in scenarios that affect server resources, such as operations such as registering users.
  • 是否缓存: Because the application scenarios of the two are different, browsers generally cache Get requests, but rarely cache Post requests.
  • 发送的报文格式: The entity part of the message of the Get request is empty, and the entity part of the message of the Post request is generally the data sent to the server.
  • 安全性: The Get request can put the request parameters into the url and send it to the server. Compared with the Post request, this method is not safe, because the requested url will be kept in the history.
  • 请求长度: Due to the browser's limitation on the length of the url, it will affect the length of the data sent by the get request. This limit is specified by the browser, not by the RFC.
  • 参数类型: The parameter passing of post supports more data types.

The difference between POST and PUT requests

  • PUTThe request is to send data to the server to modify the content of the data, but it will not increase the type of data, etc., that is to say, no matter how many PUT operations are performed, the result is not different. (can be understood as yes 更新数据)
  • POSTA request is to send data to the server. This request will change resources such as the type of data, and it will create new content. (can be understood as yes 创建数据)

OPTIONS request method and usage scenarios

  • The OPTIONS method is used to request the functional options that can be used by the resource identified by the Request-URI during the request/response communication. Through this method, the client can decide what necessary action to take on the resource or understand the performance of the server before making a specific resource request. Responses for this request method cannot be cached.

  • There are two main purposes of the OPTIONS request method

    • Get all HTTP request methods supported by the server;
    • Used to check access rights. For example: when performing CORS cross-domain resource sharing, for complex requests, use the OPTIONS method to send a sniffing request to determine whether there is access to the specified resource.

Guess you like

Origin blog.csdn.net/weixin_40119412/article/details/130447095