Home  >  Article  >  Backend Development  >  What is the role of Content-Type?

What is the role of Content-Type?

藏色散人
藏色散人Original
2019-04-11 11:53:575117browse

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

In the response, the Content-Type header tells the client the content type of the actual content returned. Browsers perform MIME lookups in some cases and do not necessarily honor the value of this header; to prevent this behavior, the header X-Content-Type-Options can be set to nosniff.

In the request (such as POST or PUT), the client tells the server the type of data actually sent.

Syntax:

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

Directions:

media-type

The MIME type of the resource or data.

charset

Character encoding standard.

boundary

A boundary is required for multipart entities, which consists of 1 to 70 characters from a set of characters known to be very robust through email gateways, rather than ending in whitespace. It is used to encapsulate the boundaries of multiple parts of a message.

Example

##Content-Type in HTML form

In the POST request generated by submitting the HTML form, request The Content-Type of the header is specified by the enctype attribute on the
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 header looks like this (some headers are omitted here):

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

---------------------------974767299852498929531610575
Content-Disposition: form-data; name="description" 

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

(content of the uploaded file foo.txt)
---------------------------974767299852498929531610575

Browser compatibility

What is the role of Content-Type?

The above is the detailed content of What is the role of Content-Type?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn