The difference between the GET and POST methods of HTTP requests
In the request-response between the client and the server, the two most commonly used methods are: GET and POST.
- GET-Requests data from the specified resource.
- POST-submits the data to be processed to the specified resource
Get method
Note that the query string (name/value pair) is sent in the URL of the GET request:
/test/demo_form.asp?name1=value1&name2=value2
- Requests can be cached
- Request remains in browser history
- Requests can be bookmark-Favorites
- The request should not be used when processing sensitive data
- Request has a length limit
- Requests should only be used to retrieve data
Post method
Note that the query string (name/value pair) is sent in the HTTP message body of the POST request:
POST /test/demo_form.asp HTTP/1.1Host: w3schools.comname1=value1&name2=value2
Compare GET to POST
Method |
GET |
POST |
Cache |
can be cached |
Cannot be cached |
|
Encoding type |
application/x-www-form-urlencoded |
Application/x-www-form-urlencoded or Multipart/form-data. Use multiple encodings for binary data. |
Limits on the length of data |
Yes. The GET method adds data to the URL when the data is sent, and the length of the URL is restricted (the maximum URL length is 2048 characters) |
Unlimited. |
Restrictions on data types |
Only ASCII characters are allowed |
There is no limit. Binary data is also allowed. |
Security |
GET is less secure than POST because the data being sent is part of the URL. Never use GET when sending passwords or other sensitive information |
POST is more secure than GET because parameters are not saved in the browser history or Web server logs. |
Visibility of |
The data is visible to everyone in the URL. |
The data is not displayed in the URL. |
Other HTTP Request Methods
- HEAD is the same as GET, but returns only the HTTP header and does not return the document body.
- The PUT upload specifies the URI representation.
- Delete Deletes the specified resource.
- OPTIONS returns the HTTP methods supported by the server
- Connect converts the request connection to a transparent TCP/IP channel.
The difference between the GET and POST methods of HTTP requests