是否可以使用一个Set-Cookie设置多个Cookie? [英] Is it possible to set more than one cookie with a single Set-Cookie?
问题描述
一个HTTP Set-Cookie指令只能保存一个Cookie,是不是?我的意思是,一个 name = value
对?
One HTTP Set-Cookie directive can only hold one cookie, is it right? I mean, one single name=value
pair?
推荐答案
The original cookie specification of Netscape (see this cached version) does not say anything about listing multiple cookie declarations.
但是从 定义的Set-Cookie a href =http://tools.ietf.org/html/rfc2109 =nofollow noreferrer> RFC 2109 允许以逗号分隔的Cookie声明列表:
But as of Set-Cookie as defined by RFC 2109 allows a comma separated list of cookie declaration:
非正式地,Set-Cookie响应头包括令牌Set-Cookie :,后面是一个或多个cookie的逗号分隔列表。每个Cookie以NAME = VALUE对开头,后跟零个或多个分号分隔的属性值对。
Informally, the Set-Cookie response header comprises the token Set-Cookie:, followed by a comma-separated list of one or more cookies. Each cookie begins with a NAME=VALUE pair, followed by zero or more semi-colon-separated attribute-value pairs.
适用于 RFC 2965 定义的 Set-Cookie2 : The same applies to Set-Cookie2 as defined by RFC 2965: 非正式地,Set-Cookie2响应头包括令牌Set-Cookie2 :,后面是一个或多个cookie的逗号分隔列表。每个Cookie以NAME = VALUE对开头,后跟零个或多个分号分隔的属性值对。 Informally, the Set-Cookie2 response header comprises the token Set-Cookie2:, followed by a comma-separated list of one or more cookies. Each cookie begins with a NAME=VALUE pair, followed by zero or more semi-colon-separated attribute-value pairs. 大多数用户代理仍然遵循Netscape的原始规范,我宁愿建议只使用自己的 Set-Cookie 头字段声明每个cookie。 But since most user agents still follow Netscape’s original specification, I would rather suggest to just declare each cookie with its own Set-Cookie header field. 也是最新的 RFC 6265 反映的内容: This is also what the latest RFC 6265 reflects: 源服务器不应将多个Set-Cookie头字段折叠为 Origin servers SHOULD NOT fold multiple Set-Cookie header fields into
a single header field. The usual mechanism for folding HTTP headers
fields (i.e., as defined in [RFC2616]) might change the semantics of
the Set-Cookie header field because the %x2C (",") character is used
by Set-Cookie in a way that conflicts with such folding. 这篇关于是否可以使用一个Set-Cookie设置多个Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
a单个头字段。用于折叠HTTP头
字段(即,如[RFC2616]中定义的)的通常机制可以改变
的Set-Cookie头字段的语义,因为使用%x2C(,)字符
由Set-Cookie以与此类折叠冲突的方式。