Html header media type

Content-Type

The HTTP Content-Type header indicates the original media type of the resource.

Usage

The HTTP Content-Type header is used to inform the client concerning the resource’s original media type. The distinction is necessary because pre-transmission, the server or intermediaries can apply one or more Content-Encoding methods. The representation that arrives may need to be revered to the original before it can be used.

The directives for the HTTP Content-Type header are the media type , charset , and boundary . The media type is a valid MIME type, and a complete list is maintained by IANA.

Example

In the first example, the original media type is text/html and uses the UTF-8 character set. Because servers are encouraged to compress resources pre-transmission, HTML files are routinely compressed. The client will use the Content-Encoding header to determine how to return their representation to the one specified by the Content-Type header.

Content-Type: text/html; charset=UTF-8 

In the second example, a multipart response is sent. Each of the sections is separated by the specified boundary phrase. In this case, the boundary between parts is «——«.

Content-Type: multipart/form-data; boundary=----- 

Takeaway

The Content-Type header is used to inform the client as to the original, pre-encoded media type of the resource.

See also

HTTP Status Tester

Test live and from different countries the HTTP responses, redirect chains and status codes of one or multiple URLs.

  1. Cache-Control
  2. Clear-Site-Data
  3. Connection
  4. Content-Disposition
  5. Content-Encoding
  6. Content-Language
  7. Content-Length
  8. Content-Location
  9. Content-Range
  10. Content-Security-Policy
  11. Content-Security-Policy-Report-Only
  12. Cookie
  13. Cross-Origin-Embedder-Policy
  14. Cross-Origin-Opener-Policy
  15. Cross-Origin-Resource-Policy
Читайте также:  Таблица характеристики гостиниц html

Made with ♥ by SEO Expert Fili © 2022 — 2023 Licensed under CC BY-NC-ND 4.0

Источник

Content-Type

The Content-Type representation header is used to indicate the original media type of the resource (prior to any content encoding applied for sending).

In responses, a Content-Type header provides the client with the actual content type of the returned content. This header’s value may be ignored, for example when browsers perform MIME sniffing; set the X-Content-Type-Options header value to nosniff to prevent this behavior.

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

Header type Representation header
Forbidden header name no
CORS-safelisted response header yes
CORS-safelisted request header yes, with the additional restriction that values can’t contain a CORS-unsafe request header byte: 0x00-0x1F (except 0x09 (HT)), «():<>?@[\]<> , and 0x7F (DEL).
It also needs to have a MIME type of its parsed value (ignoring parameters) of either application/x-www-form-urlencoded , multipart/form-data , or text/plain .

Syntax

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

Directives

The MIME type of the resource or the data.

The character encoding standard. Case insensitive, lowercase is preferred.

For multipart entities the boundary directive is required. The directive consists of 1 to 70 characters from a set of characters (and not ending with white space) known to be very robust through email gateways. It is used to encapsulate the boundaries of the multiple parts of the message. Often, the header boundary is prepended with two dashes and the final boundary has two dashes appended at the end.

Examples

Content-Type in HTML forms

In a POST request, resulting from an HTML form submission, the Content-Type of the request 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">Submitbutton> 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 -----------------------------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-- 

Specifications

Browser compatibility

BCD tables only load in the browser

See also

Found a content problem with this page?

This page was last modified on Apr 10, 2023 by MDN contributors.

Your blueprint for a better internet.

Источник

What are All the Possible Values for HTTP “Content-Type” Header

The HTTP “Content-Type” Header is the identifier used to make the HTTP client and server understand the content or media type of the resource added in the document. It instructs the server on which media type the browser is looking for. The HTTP Content-Type header is supported by many browsers including “Google Chrome”, “Mozilla Firefox”, “Internet Explorer”, “Safari”, “Samsung browser” and “Opera”.

This blog will discuss about different values of the HTTP “Content-Type” Header.

How to Use the HTTP “Content-Type” Header?

The syntax to use the HTTP “Content-Type” Header is as follows:

Types of the Values in HTTP “Content-Type” Header

The types of the content type values used in the HTTP “Content-Type” Header are as follows:

All Values in HTTP “Content-Type” Header

There are multiple values for each content type used in the HTTP “Content-Type” Header. Let’s enlist all the possible values of each content type of the HTTP “Content-Type” Header.

Application

When an application is supposed to be added to the document, the “application” content type is used in the header. There are different types of application file formats that the HTTP supports:

    • application/java-archive
    • application/EDI-X12
    • application/javascript
    • application/xml
    • application/pdf
    • application/octet-stream
    • application/ogg
    • application/zip
    • application/xhtml+xml
    • application/x-shockwave-flash
    • application/json
    • application/x-www-form-urlencoded
    • application/ld+json
    • application/EDIFACT

    When there is a need to add the audio files to the document, the “audio” content type is used in the header. Audio can be added in different formats as follows:

    To add images in the document of different formats, there is the “image” content type and the following are the possible values for the Image content type:

      • image/gif
      • image/tiff
      • image/vnd.djvu
      • image/jpeg
      • image/svg+xml
      • image/png
      • image/x-icon
      • image/vnd.microsoft.icon

      The “multipart” content type is added to upload files or content of different types in a single document. The following four values for the “multipart” content-type are valid in HTTP:

        • multipart/mixed
        • multipart/related
        • multipart/form-data
        • multipart/alternative

        When there is a text file supposed to be added to the document, the “text” content type is used with any of the following six text format values:

          • text/css
          • text/javascript (obsolete)
          • text/plain
          • text/html
          • text/xml
          • text/csv

          To efficiently display the videos, the “video” content type is used with the following content type values:

            • video/mpeg
            • video/x-ms-wmv
            • video/x-msvideo
            • video/webm
            • video/mp4
            • video/x-flv
            • video/quicktime

            VND (Vendor-specific)

            Following are the values for the VND (Vendor-specific) content type for HTTP:

              • application/vnd.android.package-archive
              • application/vnd.openxmlformats-officedocument.presentationml.presentation
              • application/vnd.mozilla.xul+xml
              • application/vnd.oasis.opendocument.text
              • application/vnd.oasis.opendocument.presentation
              • application/vnd.oasis.opendocument.spreadsheet
              • application/vnd.ms-powerpoint
              • application/vnd.oasis.opendocument.graphics
              • application/vnd.ms-excel
              • application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
              • application/vnd.openxmlformats-officedocument.wordprocessingml.document
              • application/msword

              These are all the possible values for the HTTP “Content-Type” Header.

              Conclusion

              The HTTP “Content-Type” Header instructs the HTTP clients and server which type of file they must execute. There are multiple types of the HTTP “Content-Type” Header that includes application, audio, image, multipart, text, and video. Moreover, it comprises multiple values for these content or media types, for instance, text/html, application/pdf, audio/mpeg, etc. This blog is a good guide about different values used in the HTTP “Content-Type” header.

              About the author

              Hadia Atiq

              A Software Engineer and Technical Writer passionate about learning and spreading knowledge of the latest technology. I utilize my writing skills to help readers understand the importance and usage of modern technology.

              Источник

Оцените статью