Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 1086581 of POST

  • Revision slug: Web/HTTP/Methods/POST
  • Revision title: POST
  • Revision id: 1086581
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment

Revision Content

{{HTTPSidebar}}

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 (use application/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 
Content-Disposition: form-data; name="field1" 

value1 
--boundary 
Content-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

{{Compat}}

See also

  • {{HTTPHeader("Content-Type")}}
  • {{HTTPHeader("Content-Disposition")}}

Revision Source

<div>{{HTTPSidebar}}</div>

<p>The <strong>HTTP <code>POST</code> method</strong> sends data to the server. The type of the body of the request is indicated by the {{HTTPHeader("Content-Type")}} header. A <code>POST</code> request is typically send via an <a href="/en-US/docs/Web/Guide/HTML/Forms">HTML form</a> and results in a change on the server. In this case, the content type is selected by putting the adequate string in <dfn id="attr-fs-enctype-urlencoded">the {{htmlattrxref("enctype", "form")}} attribute of the {{HTMLElement("form")}} element or the {{htmlattrxref("formenctype", "input")}} attribute of the {{HTMLElement("input") }} or {{HTMLElement("button")}} elements</dfn>:</p>

<ul>
 <li><code>application/</code><dfn id="attr-fs-enctype-urlencoded"><code>x-www-form-urlencoded</code>: the values are encoded in key-value tuples separated by <code>'&amp;'</code>, with a <code>'='</code> 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 (use <code>application/form-data</code> instead)</dfn></li>
 <li><dfn><code>application/form-data</code></dfn></li>
 <li><dfn><code>text/plain</code></dfn></li>
</ul>

<p>When the <code>POST</code> request is sent via another method that an HTML Form, like via an {{domxref("XMLHttpRequest")}}, the body can take any type.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Request has body</th>
   <td>Yes</td>
  </tr>
  <tr>
   <th scope="row">Successful response has body</th>
   <td>Yes</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Safe")}}</th>
   <td>No</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Idempotent")}}</th>
   <td>No</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Cacheable")}}</th>
   <td>Only if freshness information is included</td>
  </tr>
  <tr>
   <th scope="row">Allowed in <a href="/en-US/docs/Web/Guide/HTML/Forms">HTML forms</a></th>
   <td>Yes</td>
  </tr>
 </tbody>
</table>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
POST /index.html
</pre>

<h2 id="Example">Example</h2>

<p>A simple form using the default <code>application/x-www-form-urlencoded</code> content type:</p>

<pre class="line-numbers  language-html">
POST / HTTP/1.1
Host: foo.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 13

say=Hi&amp;to=Mom</pre>

<p>A form using the <code>multipart/form-data</code> content type:</p>

<pre>
POST /test.html HTTP/1.1 
Host: example.org 
Content-Type: multipart/form-data;boundary="boundary" 

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

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

value2</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Title</th>
  </tr>
  <tr>
   <td>{{RFC("7231", "POST", "4.3.3")}}</td>
   <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p class="hidden">To contribute to this compatibility data, please write a pull request against this file: <a href="https://github.com/mdn/browser-compat-data/blob/master/http/methods.json">https://github.com/mdn/browser-compat-data/blob/master/http/methods.json</a>.</p>

<p>{{Compat}}</p>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{HTTPHeader("Content-Type")}}</li>
 <li>{{HTTPHeader("Content-Disposition")}}</li>
</ul>
Revert to this revision