preface

A total of eight request types are defined in HTTP to represent different operations on a given resource, of which the most common are GET and POST requests. This paper classifies these different requests into the following aspects:

  • An introduction to the eight request types
  • Explain the difference between a GET request and a POST request

An introduction to the eight request types

A GET request

Fetch data from the server. Just fetching the data doesn’t have any other impact. For example, a GET request to access/Employee /101/ John can retrieve the details of that employee.

A POST request

Create an entity, that is, a resource without an ID. Once the request is successfully executed, the ID of the newly created entity is returned in the response to the HTTP request. We usually use POST requests to upload files or forms. For example, a POST request to access/Employee /102/ Li Si would create a new employee with ID 102.

PUT request

To update an existing entity. Update the resource by uploading the ID of the existing resource and the new entity to the server with a PUT request. For example, a PUT request to/Employee /101/ King five can update employee 101’s information

The DELETE request

Deletes resources from the server. The ID of the resource to be deleted is uploaded to the server. For example, employee 101 can be deleted with a DELETE request to/Employee /101/ Wang 5

The TRACE request

Provides a way to test what the server receives over the network when a request is made. So it will return what you sent.

A HEAD request

A HEAD request is similar to a GET request resource, but only returns the corresponding header, with no concrete response body. It also has no other impact on the server

The OPTIONS request

OPTIONS allows a client to request a request method supported by the service. The corresponding response header is Allow, which lists the supported methods very succinctly. For the server successfully processed OPTIONS below request, the content of the response: Allow: HEAD, GET, PUT, DELETE, OPTIONS

The CONNECT request

It is used to establish a network connection to a resource. Once a connection is Established, it responds with a 200 status code and a “Connectioin Established” message.

Explain the difference between a GET request and a POST request

The principle difference between

Usually when we enter a url in the browser to access a website, it’s a GET request. In HTTP request types, GET and HEAD are idempotent and are known as secure methods. Because the use of GET and HEAD requests produces no results on the server, the safe method does not produce no action at all, and by safe method we simply mean that no information is modified. According to the HTTP specification, A POST request may modify a resource on the server. For example, if a user submits an article or a reader submits a comment via POST because the resource (i.e. a page) is different after submission, or the resource has been modified, this is an “unsafe method”.

Difference in expression form

The requested data is appended to the URL as ‘? ‘Split URL and transfer data, multiple parameters with & link. The URL encoding format is ASCII encoding, not Unicode, and all non-ASCII characters are encoded before transmission. A POST request puts the requested data in the body of the HTTP request package. Therefore, the data for a GET request is exposed in the address bar, whereas the data for a POST request is not.

The size of the transmitted data

In the HTTP specification, there are no restrictions on the length of the address bar or the size of the transmitted data, but in practice, specific browsers and servers may limit the length of the URL. Therefore, when using GET requests, the data transferred is limited by the length of the URL. In theory there is no limit on POST requests, but in practice each server has a limit on the size of the data submitted by POST.

security

POST is more secure than GET. The security mentioned here is not the security method mentioned above. Instead, the GET request exposes the information to the address bar. In this case, the information may be leaked through the browser cache and historical records. POST requests do not have this problem. In addition, the data submitted by a GET request can create a cross-site Request Frogery attack, which tricks a user’s browser into sending an HTTP request to the target site by using a site’s trust in the user’s identity.