you have to parse the string programmatically and create Cookie objects and add them to the CookieCollection, use String's Split method or regular expresssions, for example

解决方案 »

  1.   

    CookieCollection是一个集合把?除了Name和Value以外Domain和Path需要么?
      

  2.   

    it depends on your application CookieCollection cc =new CookieCollection();
    string s = "SID=ARRGy4M1QVBtTU-ymi8bL6X8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlplUxq7hnBK5eqoh3E54jqk=;Domain=.google.com;Path=/,LSID=AaMBTixN1MqutGovVSOejyb8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlhCe_QqxLg00W5OZejb_UeQ=;Domain=www.google.com;Path=/accounts";
    Regex re = new Regex("([^;,]+)=([^;,]+);Domain=([^;,]+);Path=([^;,]+)", RegexOptions.IgnoreCase);
    foreach (Match m in re.Matches(s))
    {
    //name, value, path, domain
    Cookie c = new Cookie(m.Groups[1].Value, m.Groups[2].Value,m.Groups[3].Value,m.Groups[3].Value);
    cc.Add(c);
    }
      

  3.   

    在MSDN中看见Cookie的重载列表如下。最多也就能保存Name Value Path Domain4个。但是我发现我登陆Gmail的时候Cookie除了这4个属性以外还有Expires属性。我应该怎么处理?另外Cookie除了这5个以外就没有其他属性了么?
    非常感谢。。
    重载列表
    初始化 Cookie 类的新实例。[Visual Basic] Public Sub New()
    [C#] public Cookie();
    [C++] public: Cookie();
    [JScript] public function Cookie();
    使用指定的 Name 和 Value 初始化 Cookie 类的新实例。[Visual Basic] Public Sub New(String, String)
    [C#] public Cookie(string, string);
    [C++] public: Cookie(String*, String*);
    [JScript] public function Cookie(String, String);
    使用指定的 Name、Value 和 Path 初始化 Cookie 类的新实例。[Visual Basic] Public Sub New(String, String, String)
    [C#] public Cookie(string, string, string);
    [C++] public: Cookie(String*, String*, String*);
    [JScript] public function Cookie(String, String, String);
    使用指定的 Name、Value、Path 和 Domain 初始化 Cookie 类的新实例。[Visual Basic] Public Sub New(String, String, String, String)
    [C#] public Cookie(string, string, string, string);
    [C++] public: Cookie(String*, String*, String*, String*);
    [JScript] public function Cookie(String, String, String, String);
    Set-Cookie: GV=1010152ee8577-4a167ad39712d7e261ff281661974255; Domain=gmail.google.com; Path=/gmail
    Set-Cookie: GMAIL_AT=3e765fc6b8c9c44-10152ee857a; Path=/
    Set-Cookie: GMAIL_RTT=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
    Set-Cookie: GMAIL_RTT2=; Domain=google.com; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
    Set-Cookie: GMAIL_STAT=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
    Set-Cookie: GMAIL_LOGIN=; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
    Set-Cookie: GMAIL_LOGIN2=; Domain=google.com; Expires=Fri, 07-Jan-05 15:25:58 GMT; Path=/
      

  4.   

    Expires is used to set the expiry date for the cookie, you can set it to anything in the future to keep your cookie alive or anything in the past to make it expire