POST (HTTP)
HTTP |
---|
Request methods |
Header fields |
Response status codes |
Security access control methods |
Security vulnerabilities |
In computing, POST is a request method supported by HTTP used by the World Wide Web.
By design, the POST request method requests that a web server accepts the data enclosed in the body of the request message, most likely for storing it.
In contrast, the HTTP
As part of a POST request, an arbitrary amount of data of any type can be sent to the server in the body of the request message. A fields header field in the POST request usually indicates the message body's Internet media type.
Posting data
The world wide Web and HTTP are based on a number of request methods or 'verbs', including POST and GET as well as PUT, DELETE, and several others. Web browsers normally use only GET and POST, but
http://example.com/customers
, POST requests might be expected to represent new customers, each including their name, address, contact details and so on. Early website designers strayed away from this original concept in two important ways. First, there is no technical reason for a URI to textually describe the web resource subordinate to which POST data will be stored. In fact, unless some effort is made, the last part of a URI will more likely describe the web application's processing page and its technology, such as http://example.com/applicationform.php
Efforts by some influential writers to remedy the first point began as early as 1998.
That is not to say that every web form should specify method="post"
in its opening tag. Many forms are used to specify more precisely the retrieval of information from the server, without any intention of altering the main database. Search forms, for example, are ideally suited to having method="get"
specified.[4]
There are times when HTTP GET is less suitable even for data retrieval. An example of this is when a great deal of data would need to be specified in the URL. Browsers and web servers can have limits on the length of the URL that they will handle without truncation or error. Percent-encoding of reserved characters in URLs and query strings can significantly increase their length, and while Apache HTTP Server can handle up to 4,000 characters in a URL,[5] Microsoft Internet Explorer is limited to 2,048 characters in any URL.[6] Equally, HTTP GET should not be used where sensitive information, such as usernames and passwords, have to be submitted along with other data for the request to complete. Even if HTTPS is used, preventing the data from being intercepted in transit, the browser history and the web server's logs will likely contain the full URL in plaintext, which may be exposed if either system is hacked. In these cases, HTTP POST should be used.[7]
Use for submitting web forms
When a web browser sends a POST request from a
For example, the key-value pairs
Name: Gareth Wylie Age: 24 Formula: a+b == 21
are encoded as
Name=Gareth+Wylie&Age=24&Formula=a%2Bb+%3D%3D+21
Starting with HTML 4.0, forms can also submit data in
The special case of a POST to the same page that the form belongs to is known as a postback.
Affecting server state
Per RFC 7231, the POST method is not idempotent, meaning that multiple identical requests might not have the same effect as transmitting the request only once. POST is therefore suitable for requests which change the state each time they are performed, for example submitting a comment to a blog post or voting in an online poll. GET is defined to be nullipotent, with no side-effects, and idempotent operations have "no side effects on second or future requests".[10][11] For this reason, web crawlers such as search engine indexers normally use the GET and HEAD methods exclusively, to prevent their automated requests from performing such actions.
However, there are reasons why POST is used even for idempotent requests, notably if the request is very long. Due to restrictions on URLs, the query string the GET method generates may become very long, especially due to percent-encoding.[10]
References
- ^ S2CID 14399078. Retrieved 2014-07-24.
The POST method requests that the target resource process the representation enclosed in the request according to the resource's own specific semantics.
- ^ Berners-Lee, Tim (1998). "Cool URIs don't change". W3C. Retrieved 17 October 2012.
- ^ Friedman, Mike (2009). "Using HTTP PUT and DELETE methods in web applications". Retrieved 17 October 2012.
- ^ "Form submission". HTML 4.01 Specification. W3C. 1999. Retrieved 17 October 2012.
- ^ Rigsby, Dan (2008). "REST and Max URL Size". Archived from the original on 4 November 2012. Retrieved 17 October 2012.
- ^ "Maximum URL length is 2,048 characters in Internet Explorer". Microsoft.
- S2CID 14399078. Retrieved 2014-07-25.
- ^ Berners-Lee, Tim; Connolly, Dan (22 September 1995). "Hypertext Markup Language - 2.0 - Forms". World Wide Web Consortium. Retrieved 15 January 2011.
- ^ "Forms in HTML documents".
- ^ a b Korpela, Jukka (28 September 2003). "Methods GET and POST in HTML forms - what's the difference?". Tampere University of Technology. Retrieved 15 January 2011.
- ^ RFC 7231, 4.2.1 Safe Methods
External links
- Straightforward definition of POST
- POST verb in HTTP specification
- "Deploying Storage in Google Cloud Platform", Google Cloud Certified Associate Cloud Engineer Study Guide, Wiley, 2019-03-28, pp. 275–308, S2CID 241576882