问题描述
我想知道我是否可以返回响应标题
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?
谢谢!
推荐答案
您需要查看标题字段的定义:
You need to look at the definition of the header field:
Content-Type =Content-Type:media-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协议是否支持响应头中的多种内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!