音标:英 [ˈkɒntent taɪp],美 [ˈkɑːntent taɪp]
意思:Content-Type 是 HTTP 协议中的核心头部字段,用于描述数据的媒体类型或格式,帮助接收方正确解析内容。它就像数据的“身份标签”,告诉浏览器或客户端“这是 HTML 网页”“这是 JSON 数据”还是“这是图片”。例如,text/html 表示 HTML 文档,application/json 表示 JSON 格式数据。
用法:作为 HTTP 头部字段,Content-Type 需在请求或响应中显式声明。服务器通过它告知客户端数据格式,客户端也可通过它告诉服务器发送的数据类型(如表单提交时使用 application/x-www-form-urlencoded)。
When a browser receives Content-Type: text/html, it renders the data as a webpage.
(当浏览器收到 Content-Type: text/html 时,会将数据渲染为网页。)
The API returns JSON data with Content-Type: application/json in the response header.
(该 API 在响应头中用 Content-Type: application/json 声明返回 JSON 数据。)
An error occurred while attempting to load the content type names.
(尝试加载内容类型名称时发生错误。)
Simple content type cannot define any order set.
(简单内容类型无法定义任何顺序集。)
The Content-Type header cannot be set to a multipart type for this request.
(此请求的 Content-Type 头部不能设置为多部分类型。)
These settings apply to the % field in every content type in which it appears.
(这些设置适用于所有出现该字段的内容类型。)
The derived type and the base type must have the same content type.
(派生类型和基类型必须具有相同的内容类型。)
For this exercise, you'll create a movie content type.
(在本练习中,你将创建一个电影内容类型。)
The server uses Content-Type: image/png to indicate the response is a PNG image.
(服务器用 Content-Type: image/png 表示响应是 PNG 图片。)
When sending form data, set Content-Type: multipart/form-data for file uploads.
(发送表单数据时,文件上传需设置 Content-Type: multipart/form-data。)
Content-Type header:Content-Type 头部(HTTP 协议中用于声明数据类型的字段)
application/json:JSON 格式数据类型(最常用的 API 数据交换格式)
text/html:HTML 文档类型(网页的标准格式)
multipart/form-data:多部分表单数据类型(用于文件上传)
application/xml:XML 格式数据类型(传统结构化数据格式)
content type mapping:内容类型映射(服务器将文件扩展名与 Content-Type 关联的配置)
set Content-Type:设置 Content-Type(开发者需手动或通过框架配置该头部)
Content-Type 的准确使用是网络通信的基础——就像写信时注明“信件”“包裹”或“易碎品”,它确保数据被“正确解读”而非“误读”。下次调用 API 或开发网页时,不妨留意响应头中的这个“数据身份证”,它或许就是解决数据解析错误的关键。