问题描述
我想知道我是否可以返回响应头
I'm wondering if I can return the response header
Content-Type: application/json text/json
这不合法吗?
HTTP 协议规定 Content-Type 应该是 mediaType 并且 mediaType 定义如下:
The HTTP protocol states that Content-Type should be of mediaType and that mediaType is defined as the following:
media-type = type "/" subtype *( ";" parameter )
type = token
subtype = token
但是我无法解释这意味着什么,有人可以启发我吗?
But I'm having trouble interpreting what this means, can anyone enlighten me?
谢谢!
推荐答案
需要看头域的定义:
http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.14.17
Content-Type = "Content-Type" ":" 媒体类型
Content-Type = "Content-Type" ":" media-type
所以它采用单一媒体类型,由您上面引用的语法定义.
so it takes a single media-type, which is defined by the grammar you quoted above.
所以答案是:单一类型/子类型,后跟可选参数.
So the answer is: a single type/subtype, followed by optional parameters.
这篇关于HTTP 协议是否支持响应标头中的多种内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!