Various request methods of Http (detailed explanation)

Summary

We know that when we visit various web pages, the fundamental reason why we can see the page is that an http request is sent and then a response is received, so that the page will pop up. Or when we upload some photos and videos, the reason why we can upload them successfully is because we upload them through http requests, thus putting the resources on the Internet.

insert image description here
When the client sends a request to the server, we divide it into different http request methods for requests with different intentions.

1. GET request

The GET method is the most common and simplest http request method, which is mainly used to obtain resources. That is to say, whatever my client requests, your server will return it to me as it is.
What I request is text, and you return it as it is; what I request is a program like CGI, and you return the running result to me.
insert image description here

2. POST request

The POST method is mainly used to transmit the body of the entity.

In other words, when the client needs to transmit something to the server, the POST method can be used at this time. Can the GET method be used? Of course, it is also possible, but we do not recommend using the GET method to transfer the body of the entity .

insert image description here

At this time, we will have a classic interview question: ahem, what is the difference between GET and POST?

3. The difference between GET and POST

Here we can refer to what the w3c said:

1. GET is harmless when the browser falls back, and POST will submit the request again.

2. The URL address generated by GET can be Bookmarked, but not POST.

3. GET requests will be actively cached by the browser, but POST will not, unless manually set.

4. GET requests can only be url encoded, while POST supports multiple encoding methods.

5. GET request parameters will be kept intact in the browser history, while parameters in POST will not be kept.

6. The parameters transmitted in the URL of the GET request have a length limit, but there is no POST.

7. For the data type of the parameter, GET only accepts ASCII characters, while POST has no restrictions. .

8. GET is less secure than POST, because the parameters are directly exposed on the URL, so it cannot be used to transfer sensitive information.

9. GET parameters are passed through the URL, and POST is placed in the Request body.

4. PUT request

The PUT method is mainly used to transfer files, just like the file upload of the FTP protocol.
However, because the PUT method of Http/1.1 does not have an authentication mechanism, there are security issues, so ordinary websites do not use this method for file transfer.

5. HEAD request

The HEAD request is mainly used to obtain the message header

The HEAD method is the same as the GET method, except that the body of the message is not returned. It is only used to determine the validity of the request and the update date and time of the resource.

insert image description here

6. DELETE request

The DELETE method is mainly used to delete a resource, which is completely opposite to PUT.
At the same time, this method does not have an authentication mechanism, so general websites will not open it for use.

7. OPTIONS request

The OPTIONS method is used to query: what http methods are supported by the specified resource requested.
insert image description here

Guess you like

Origin blog.csdn.net/weixin_46726346/article/details/122901302