1

If I create a cookie with the value 'ë' on the server, it becomes 'ë' when I read it on the client side.

This only occurs with IE (10). I don't get this issue with other browsers (Chrome and Firefox).

The way the cookie is created:

HttpContext.Current.Response.Cookies.Add(new HttpCookie("test", "ë"));
4

1 回答 1

0

根据RFC 2109(第 4.2.2 节)和RFC 2616(第 2.2、4.2 节),HTTP 标头只能在 ISO-8859-1 中传输。(有一个例外,但这主要用于 MIME,在 HTTP 中几乎从未见过。)由于 ISO-8859-1 实际上只是一系列八位字节,服务器可以选择使用不同的编码(UTF8,在这种情况下)如果它愿意,因为无论如何 cookie 都打算被客户端不透明地处理。因此,它应该在所有情况下都正确地往返,但是如果客户端尝试解析cookie,它将根据它是否遵循 RFC 得到不同的结果。

如果可能,请尽量避免在标头中发送非 ASCII 字符。HTTP 规范从未真正正确地解释这一点,因此在实践中使用时会引起痛苦和心痛。:(

于 2013-07-03T14:59:35.753 回答