POST request method
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
ThePOST HTTP method sends data to the server. The type of the body of the request is indicated by theContent-Type header.
The difference betweenPUT andPOST is thatPUT isidempotent: calling it once is no different from calling it several times successively (there are noside effects).Successive identicalPOST requests may have additional effects, such as creating the same order several times.
HTML forms typically send data usingPOST and this usually results in a change on the server.For HTML forms the format/encoding of the body content is determined by theenctype attribute of the<form> element or theformenctype attribute of the<input> or<button> elements.The encoding may be one of the following:
application/x-www-form-urlencoded: the keys and values are encoded in key-value tuples separated by an ampersand (&), with an equals symbol (=) between the key and the value (e.g.,first-name=Frida&last-name=Kahlo).Non-alphanumeric characters in both keys and values arepercent-encoded: this is the reason why this type is not suitable to use with binary data and you should usemultipart/form-datafor this purpose instead.multipart/form-data: each value is sent as a block of data ("body part"), with a user agent-defined delimiter (for example,boundary="delimiter12345") separating each part.The keys are described in theContent-Dispositionheader of each part or block of data.text/plain
When thePOST request is sent following afetch() call, or for any other reason than an HTML form, the body can be any type.As described in the HTTP 1.1 specification,POST is designed to allow a uniform method to cover the following functions:
- Annotation of existing resources
- Posting a message to a bulletin board, newsgroup, mailing list, or similar group of articles
- Adding a new user through a signup form
- Providing a block of data, such as the result of submitting a form, to a data-handling process
- Extending a database through an append operation
| Request has body | Yes |
|---|---|
| Successful response has body | Yes |
| Safe | No |
| Idempotent | No |
| Cacheable | Only if freshness information is included |
| Allowed inHTML forms | Yes |
In this article
Syntax
POST <request-target>["?"<query>] HTTP/1.1<request-target>Identifies the target resource of the request when combined with the information provided in the
Hostheader.This is an absolute path (e.g.,/path/to/file.html) in requests to an origin server, and an absolute URL in requests to proxies (e.g.,http://www.example.com/path/to/file.html).<query>OptionalAn optional query component preceded by a question-mark
?.Often used to carry identifying information in the form ofkey=valuepairs.
Examples
>URL-encoded form submission
A form usingapplication/x-www-form-urlencoded content encoding (the default) sends a request where the body contains the form data inkey=value pairs, with each pair separated by an& symbol, as shown below:
POST /test HTTP/1.1Host: example.comContent-Type: application/x-www-form-urlencodedContent-Length: 27field1=value1&field2=value2Multipart form submission
Themultipart/form-data encoding is used when a form includes files or a lot of data.This request body delineates each part of the form using a boundary string.An example of a request in this format:
POST /test HTTP/1.1Host: example.comContent-Type: multipart/form-data;boundary="delimiter12345"--delimiter12345Content-Disposition: form-data; name="field1"value1--delimiter12345Content-Disposition: form-data; name="field2"; filename="example.txt"value2--delimiter12345--TheContent-Disposition header indicates how the form data should be processed, specifying the fieldname andfilename, if appropriate.
Specifications
| Specification |
|---|
| HTTP Semantics> # POST> |