HTTP“Content-Type”的所有可能值是什么?头? [英] What are all the possible values for HTTP "Content-Type" header?

查看:136
本文介绍了HTTP“Content-Type”的所有可能值是什么?头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须先验证 Content-Type 标头值,然后再将其传递给HTTP请求。

I have to validate the Content-Type header value before passing it to HTTP request.

是否有 Content-Type 的所有可能值的特定列表?

Is there a specific list for all the possible values of Content-Type?

否则,有没有办法验证在HTTP请求中使用它之前的内容类型?

Otherwise, is there a way to validate the content type before using it in HTTP request?

推荐答案

HTTP请求中的 Content-Type 标头或响应描述消息正文的内容类型。请求中的 Accept 标头告诉服务器客户端在响应正文中期望的内容类型。内容类型使用Internet媒体类型表示。 Internet媒体类型(也称为MIME类型)表示文件包含的数据类型。

The Content-Type header in an HTTP request or response describes the content type for the message body. The Accept header in the request tells the server the content types that the client is expecting in the response body. The content types are represented using the Internet media type. The Internet media type (also known as the MIME type) indicates the type of data that a file contains.

以下是一个示例:

Content-Type: text/html

此标题表示正文内容以html格式显示。内容类型值的格式是主要类型/子类型,后跟可选的分号分隔属性 - 值对(称为参数)。

This header indicates that the body content is presented in the html format. The format of the content type values is a primary type/subtype followed by an optional semicolon delimited attribute-value pairs (known as parameters).

Internet媒体类型广泛根据主要(或初始) Content-Type 标题分为以下类别:

The Internet media types are broadly classified in to the following categories on the basis of the primary (or initial) Content-Type header:


  • 文字:此类型表示内容为纯文本,无需特殊软件即可阅读内容。子类型表示有关内容的更具体的详细信息,客户端可以使用该详细信息进行特殊处理(如果有)。例如, Content-Type: text / html 表示正文内容为html,客户端可以使用此提示在显示响应时启动渲染引擎。

  • multipart :如名称所示,此类型由独立数据类型的多个部分组成。例如, Content-Type: multipart / form-data 用于提交包含文件,非ASCII数据和二进制数据的表单。

  • 消息:此类型封装了更多消息。它允许消息包含其他消息或指向其他消息的指针。例如, Content-Type 消息/部分内容类型允许将大型消息分解为更小的消息。然后,客户端(用户代理)可以通过将所有损坏的消息放在一起来读取完整的消息。

  • 图像:此类型表示图像数据。例如, Content-Type: image / png 表示正文内容是.png图片。

  • audio :此类型表示音频数据。例如, Content-Type: audio / mpeg 表示正文内容为MP3或其他MPEG音频。

  • 视频:此类型表示视频数据。例如 Content-Type: video / mp4 表示正文内容为MP4视频。

  • 应用程序:此类型表示应用程序数据或二进制数据。例如, Content-Type application / json ; charset = utf-8 指定内容采用UTF-8字符编码编码的 JavaScript Object Notation(JSON)格式。

  • text: This type indicates that the content is plain text and no special software is required to read the contents. The subtype represents more specific details about the content, which can be used by the client for special processing, if any. For instance, Content-Type: text/html indicates that the body content is html, and the client can use this hint to kick rendering engine while displaying the response.
  • multipart: As the name indicates, this type consists of multiple parts of the independent data types. For instance, Content-Type: multipart/form-data is used for submitting forms that contain the files, non-ASCII data, and binary data.
  • message: This type encapsulates more messages. It allows messages to contain other messages or pointers to other messages. For instance, the Content-Type: message/partial content type allows for large messages to be broken up into smaller messages. The full message can then be read by the client (user agent) by putting all the broken messages together.
  • image: This type represents the image data. For instance, Content-Type: image/png indicates that the body content is a .png image.
  • audio: This type indicates the audio data. For instance, Content-Type: audio/mpeg indicates that the body content is MP3 or other MPEG audio.
  • video: This type indicates the video data. For instance Content-Type:, video/mp4 indicates that the body content is MP4 video.
  • application: This type represents the application data or binary data. For instance, Content-Type: application/json; charset=utf-8 designates the content to be in the JavaScript Object Notation (JSON) format, encoded with UTF-8 character encoding.

要参考完整列表,请访问互联网号码分配机构(IANA)的网站www.iana.org/assignments/media-types/media-types.xhtmlrel =noreferrer>媒体类型

To refer to the complete list, visit the website of Internet Assigned Numbers Authority (IANA) at Media Types

这篇关于HTTP“Content-Type”的所有可能值是什么?头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆