HTTP协议是否支持响应头中的多种内容类型? [英] Does the HTTP Protocol support multiple content types in response headers?

查看:427
本文介绍了HTTP协议是否支持响应头中的多种内容类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我是否可以返回响应标题

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:

http://greenbytes.de/tech/webdav/rfc2616.html#rfc.section.14.17

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协议是否支持响应头中的多种内容类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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