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 1091267 of Content-Type

  • Revision slug: Web/HTTP/Headers/Content-Type
  • Revision title: Content-Type
  • Revision id: 1091267
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment added boundary

Revision Content

{{HTTPSidebar}}

The Content-Type entity header is used to indicate the media type of the resource.

In responses, a Content-Type header tells the client what the content type of the returned content actually is.

In requests, (such as {{HTTPMethod("POST")}} or {{HTTPMethod("PUT")}}), the client tells the server what type of data is actually sent.

Header type {{Glossary("Entity header")}}
{{Glossary("Forbidden header name")}} no

Syntax

Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something

Directives

media-type
The mime type of the resource or the data.
charset
The character encoding standard.
boundary
For multipart entities the boundary directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message.

Examples

Content-Type in HTML forms

In a {{HTTPMethod("POST")}} request, resulting from an HTML form submission, the Content-Type of the request is specified by the enctype attribute on the {{HTMLElement("form")}} element.

<form action="/" method="post" enctype="multipart/form-data">
  <input type="text" name="description" value="some text">
  <input type="file" name="myFile">
  <button type="submit">Submit</button>
</form>

The request looks something like this (less interesting headers are omitted here):

POST /foo HTTP/1.1
Content-Length: 68137
Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
Content-Disposition: form-data; name="description"
---------------------------974767299852498929531610575

some text

---------------------------974767299852498929531610575
Content-Disposition: form-data; name="myFile"; filename="foo.txt" 
Content-Type: text/plain 

(content of the uploaded file foo.txt)

---------------------------974767299852498929531610575

Specifications

Specification Title
{{RFC("7231", "Content-Type", "3.1.1.5")}} Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content

Browser compatibility

{{Compat}}

See also

  • {{HTTPHeader("Accept")}}

Revision Source

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

<p>The <strong><code>Content-Type</code></strong> entity header is used to indicate the media type of the resource.</p>

<p>In responses, a <code>Content-Type</code> header tells the client what the content type of the returned content actually is.</p>

<p>In requests, (such as {{HTTPMethod("POST")}} or {{HTTPMethod("PUT")}}), the client tells the server what type of data is actually sent.</p>

<table class="properties">
 <tbody>
  <tr>
   <th scope="row">Header type</th>
   <td>{{Glossary("Entity header")}}</td>
  </tr>
  <tr>
   <th scope="row">{{Glossary("Forbidden header name")}}</th>
   <td>no</td>
  </tr>
 </tbody>
</table>

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

<pre class="syntaxbox">
Content-Type: text/html; charset=utf-8
Content-Type: multipart/form-data; boundary=something
</pre>

<h2 id="Directives">Directives</h2>

<dl>
 <dt><code>media-type</code></dt>
 <dd>The <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">mime type</a> of the resource or the data.</dd>
 <dt>charset</dt>
 <dd>The character encoding standard.</dd>
 <dt>boundary</dt>
 <dd>For multipart entities the <code>boundary</code> directive is required, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, and not ending with white space. It is used to encapsulate the boundaries of the multiple parts of the message.</dd>
</dl>

<h2 id="Examples">Examples</h2>

<h3 id="Content-Type_in_HTML_forms"><code>Content-Type</code> in HTML forms</h3>

<p>In a {{HTTPMethod("POST")}} request, resulting from an HTML form submission, the <code>Content-Type</code> of the request is specified by the <code>enctype</code> attribute on the {{HTMLElement("form")}} element.</p>

<pre class="brush: html">
&lt;form action="/" method="post" enctype="multipart/form-data"&gt;
  &lt;input type="text" name="description" value="some text"&gt;
  &lt;input type="file" name="myFile"&gt;
  &lt;button type="submit"&gt;Submit&lt;/button&gt;
&lt;/form&gt;
</pre>

<p>The request looks something like this (less interesting headers are omitted here):</p>

<pre>
POST /foo HTTP/1.1
Content-Length: 68137
Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
Content-Disposition: form-data; name="description"
---------------------------974767299852498929531610575

some text

---------------------------974767299852498929531610575
Content-Disposition: form-data; name="myFile"; filename="foo.txt" 
Content-Type: text/plain 

(content of the uploaded file foo.txt)

---------------------------974767299852498929531610575
</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", "Content-Type", "3.1.1.5")}}</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">The compatibility table in this page is generated from structured data. If you’d like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data/README.md">https://github.com/mdn/browser-compat-data/README.md</a> and send us a pull request</p>

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

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

<ul>
 <li>{{HTTPHeader("Accept")}}</li>
</ul>
Revert to this revision