我有这个功能来检索 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 中调试请求时,我得到了这个:
为什么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/