【原】把CookieCollection集合读取成字符阅读形式

用【一个到多个Cookie的字符串添加到CookieCollection集合中】把字符添加成CookieCollection集合。

然后就可以用以下的代码把读成取阅读形式

string str = "SID=ARRGy4M1QVBtTU-ymi8bL6X8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlplUxq7hnBK5eqoh3E54jqk=;";

str += "RID=d152JuO1Hc3uaeWm7%2FlB3eHjUrdMUBvIjGIQEOpyO3Ek3SJLsT7ryA;";

str += "Domain=s.google.com;";

str += "Path=/,LSID=AaMBTixN1MqutGovVSOejyb8mVkctYbSbyDgdH8inu48rh_7FFxHE6MKYwqBFAJqlhCe_QqxLg00W5OZejb_UeQ=;";

str += "Domain=www.google.com;Path=/accounts";



CookieCollection cc = smHWR.strCokAddCol(str, "http://www.google.com/");



Console.WriteLine(ColToStr(cc));



public static String ColToStr(CookieCollection cc)

{

	List<Cookie> cooklist = new List<Cookie>(); 

	foreach (Cookie c in cc)

	{

		cooklist.Add(c);

	}

	StringBuilder sbc = new StringBuilder();



	foreach (Cookie cookie in cooklist)

	{
                //变成"Name={1};Value={5};Domain={0};Path={2},"就可以保存Cookie

		sbc.AppendFormat("Domain:{0}\nPath:{2}\nName:{1}\nValue:{5}\n\n",

			cookie.Domain, cookie.Name, cookie.Path, cookie.Port,

			cookie.Secure.ToString(), cookie.Value);

	}

	return  sbc.ToString();

}

你可能感兴趣的:(Collection)