POST Method

POST is an HTTP method used to send data to a server to create/update a resource. The HTTP POST method is used to create or add a resource on the server. Typically, the POST request adds a new resource to the server, while the PUT request replaces an existing resource on the server.

The type of the body of the request is indicated by the Content-Type header. application/x-www-form-urlencoded is the keys and values are encoded in key-value tuples separated by ‘&’, with a ‘=’ between the key and the value. 

For example, the HTTP POST request method is used by browsers when submitting HTML form data to the server or when submitting data using jQuery/AJAX requests.

Syntax

POST /test

Example

In the POST method, the data sent to the server with POST is stored in the request body of the HTTP request. A simple form using the default application/x-www-form-urlencoded content type:

POST /test HTTP/1.1
Host: apitier.com 
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

field1=value1&field2=value2
POST /test HTTP/1.1
Host: apitier.com 
Content-Type: application/x-www-form-urlencoded
Content-Length: 27

name=Sam&city=london

Above the example query string (name/city) is sent in the HTTP message body of a POST request.

Characteristics

  • The POST requests do not get cached.
  • The POST requests do not remain in the browser history.
  • The POST requests cannot be bookmarked as they do not appear in the URL.
  • The POST requests have no restrictions on data length.
  • The POST method can be used to send ASCII as well as binary data.

Advantages of the POST Method

  • You can keep the data private.
  • The POST method can be used to send binary as well as ASCII data.
  • It is a secure method as its requests do not remain in browser history.
  • It is very useful when you do not know the URL to keep any resource.

Click here to get more information about HTTP Status Codes