The HTTP POST
method sends data to the server. The type of the body of the request is indicated by the {{HTTPHeader("Content-Type")}} header. A POST
request is typically send via an HTML form and results in a change on the server. In this case, the content type is selected by putting the adequate string in the {{htmlattrxref("enctype", "form")}} attribute of the {{HTMLElement("form")}} element or the {{htmlattrxref("formenctype", "input")}} attribute of the {{HTMLElement("input") }} or {{HTMLElement("button")}} elements:
application/
x-www-form-urlencoded
: the values are encoded in key-value tuples separated by'&'
, with a'='
between the key and the value. Non-alphanumeric characters are {{glossary("percent encoded")}}: this is the reason why this type is not suitable to use with binary data (useapplication/form-data
instead)application/form-data
text/plain
When the POST
request is sent via another method that an HTML Form, like via an {{domxref("XMLHttpRequest")}}, the body can take any type.
Request has body | Yes |
---|---|
Successful response has body | Yes |
{{Glossary("Safe")}} | No |
{{Glossary("Idempotent")}} | No |
{{Glossary("Cacheable")}} | Only if freshness information is included |
Allowed in HTML forms | Yes |
Syntax
POST /index.html
Example
A simple form using the default application/x-www-form-urlencoded
content type:
POST / HTTP/1.1 Host: foo.com Content-Type: application/x-www-form-urlencoded Content-Length: 13 say=Hi&to=Mom
A form using the multipart/form-data
content type:
POST /test.html HTTP/1.1 Host: example.org Content-Type: multipart/form-data;boundary="boundary" --boundary Cache-Disposition: form-data; name="field1" value1 --boundary Cache-Disposition: form-data; name="field2"; filename="example.txt" value2
Specifications
Specification | Title |
---|---|
{{RFC("7231", "POST", "4.3.3")}} | Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content |
Browser compatibility
To contribute to this compatibility data, please write a pull request against this file: https://github.com/mdn/browser-compat-data/blob/master/http/methods.json.
{{Compat}}
See also
- {{HTTPHeader("Content-Type")}}
- {{HTTPHeader("Cache-Disposition")}}