docs.rodeo

MDN Web Docs mirror

POST

{{HTTPSidebar}} 

The POST HTTP method sends data to the server. The type of the body of the request is indicated by the {{HTTPHeader("Content-Type")}}  header.

The difference between {{HTTPMethod("PUT")}}  and POST is that PUT is {{Glossary("idempotent")}} : calling it once is no different from calling it several times successively (there are no side effects). Successive identical POST requests may have additional effects, such as creating the same order several times.

HTML forms typically send data using POST and this usually results in a change on the server. For HTML forms the format/encoding of the body content is determined by the enctype attribute of the {{HTMLElement("form")}}  element or the formenctype attribute of the {{HTMLElement("input") }}  or {{HTMLElement("button")}}  elements. The encoding may be one of the following:

When the POST request is sent following a {{domxref("Window/fetch", "fetch()")}}  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:

Request has body Yes
Successful response has body Yes
`{{Glossary("Safe/HTTP", "Safe")}}`  No
`{{Glossary("Idempotent")}}`  No
`{{Glossary("Cacheable")}}`  Only if freshness information is included
Allowed in HTML forms Yes

Syntax

POST <request-target>["?"<query>] HTTP/1.1

Examples

URL-encoded form submission

A form using application/x-www-form-urlencoded content encoding (the default) sends a request where the body contains the form data in key=value pairs, with each pair separated by an & symbol, as shown below:

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

field1=value1&field2=value2

Multipart form submission

The multipart/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.1
Host: example.com
Content-Type: multipart/form-data;boundary="delimiter12345"

--delimiter12345
Content-Disposition: form-data; name="field1"

value1
--delimiter12345
Content-Disposition: form-data; name="field2"; filename="example.txt"

value2
--delimiter12345--

The {{HTTPHeader("Content-Disposition")}}  header indicates how the form data should be processed, specifying the field name and filename, if appropriate.

Specifications

{{Specifications}} 

Browser compatibility

{{Compat}} 

See also

In this article

View on MDN