用于将单个HTTP标头的多个值添加到请求或响应的标准 [英] Standard for adding multiple values of a single HTTP Header to a request or response

查看:941
本文介绍了用于将单个HTTP标头的多个值添加到请求或响应的标准的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想将值列表添加为HTTP标头,是否有标准方法可以执行此操作?我在RFC 822中找不到任何(我可以很容易理解)。例如,
逗号分隔值标准或分号分隔值。是否有标准?

If I want to add a list of values as an HTTP Header, is there a standard way to do this? I couldn't find anything (that I could easily understand) in RFC 822. For example, is comma separated values standard or semi-colon separated values. Is there a standard at all?

示例:

Key: value1;value2;value3


推荐答案

你想要拿走看一下HTTP规范 RFC 2616

You'll want to take a look at the HTTP spec RFC 2616 where it says:



a消息的多个消息头字段与
相同的字段名称可能出现在
a消息中如果该标题字段的整个
字段值是
,则定义为以逗号分隔的列表
[即#(values)]。必须有
将多个头字段
组合成一个field-name:field-value
对,而不更改消息的语义
,方法是附加每个
后续字段值到第一个,
每个用逗号分隔。因此,接收具有相同
字段名称的头字段的订单
因此对于
的组合字段值的解释是重要的
,因此是
代理当消息转发
时,不得更改
这些字段值的顺序。

Multiple message-header fields with the same field-name MAY be present in a message if and only if the entire field-value for that header field is defined as a comma-separated list [i.e., #(values)]. It MUST be possible to combine the multiple header fields into one "field-name: field-value" pair, without changing the semantics of the message, by appending each subsequent field-value to the first, each separated by a comma. The order in which header fields with the same field-name are received is therefore significant to the interpretation of the combined field value, and thus a proxy MUST NOT change the order of these field values when a message is forwarded.

这意味着什么是您可以在具有不同值的响应中多次发送相同的标头,只要这些值可以使用逗号相互附加。这也意味着你可以通过用逗号连接它们在一个标题中发送多个值。

What this means is that you can send the same header multiple times in a response with different values, as long as those values can be appended to each other using a comma. This also means that you can send multiple values in a single header by concatenating them with commas.

所以在你的情况下它将是:

So in your case it will be:

Key: value1,value2,value3

这篇关于用于将单个HTTP标头的多个值添加到请求或响应的标准的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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