c# - "$"美元字符前缀 cookie 名称

标签 c# cookies

我有这个功能来检索 CookieContainer (this.cookies) 中的响应 cookie

private void getCookies(string url)
{

  // request
  HttpWebRequest request = CreateWebRequestObject(url);
  request.CookieContainer = this.cookies;

  request.Headers.Add("Accept-Encoding", "gzip, deflate");
  request.Headers.Add("Accept-Language", " es-MX,es;q=0.8,en-us;q=0.5,en;q=0.3");
  request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";



  request.Method = "GET";
  request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2";

  // response
  using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  {
    foreach (Cookie c in response.Cookies)
    {
      this.cookies.Add(new Cookie(c.Name, c.Value, c.Path, c.Domain));


    }
  }
}

但是,当我在 Fiddler 中调试请求时,我得到了这个:

enter image description here

为什么cookie里有个“$”?

根据MSDN

public Cookie( string name, string value, string path, string domain )

name Type: System.String The name of a Cookie. The following characters must not be used inside name: equal sign, semicolon, comma, newline (\n), return (\r), tab (\t), and space character. The dollar sign character ("$") cannot be the first character.

如何删除这个字符?

最佳答案

您看到的 $ 不是 cookie 的名称;它是与 cookie 关联的属性

RFC 2109处理 HTTP 状态管理; 4.4 节专门讨论了美元符号前缀。希望对您有所帮助...

关于c# - "$"美元字符前缀 cookie 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9508017/

相关文章:

asp.net - 为什么 ASP.NET FormsAuthentication cookie 无法验证用户身份?

javascript - 无法删除 express 中的 cookie

C# 未分配的局部变量错误

c# - 当服务器返回错误时,有什么方法可以使用 WebClient 访问响应主体?

c# - 使用用户输入构建 SQL 查询字符串

ios - Flutter Webview 插件不会在 iOS 上保存 session cookie?

javascript - 仅使用 JavaScript 获取基本主机名,以便 Cookie 在整个站点范围内工作

c# - ComboBox 的值加倍 c#

c# - 如何让当前用户登录到 Windows?

javascript - 在设置 cookie 时指定到期日期时可以使用哪些日期格式?