1. 程式人生 > >c# 中 利用 CookieContainer 對 Cookie 進行序列化和反序列化校驗

c# 中 利用 CookieContainer 對 Cookie 進行序列化和反序列化校驗

pre code ads domain sga pdb spa ner main

private void Form1_Load(object sender, EventArgs e)
        {
            var cookieStr = @".CNBlogsCookie=1BE76122E154E07DE50B06784B57B7DB80CC4B6DD088F0799C7C8BF7E2700B1C4FCF7A5BEAFDF80C1C49583EAB165C6FE2C9F6AA66CD8AB3C3ACC9472B77D80E4BE6BF27BB252068FD9EEEC649D8F8570FE640C666690F; .Cnblogs.AspNetCore.Cookies=CfDJ8JcopKY7yQlPr3eegllP76OXK13q0cGGKB7QKNapzaDfcNtUmcUDkcEgwmpdbzwW-tzdC7LR0DJtpdg6PKcWEEnmcH_d5Tuu2eS9hVqx8_c_v51pQKI8N9i2-BPqA7imLU8B23_Rn6L7eQYgQlV5QIVYfGfsiblfZ4oVdZpyQh_ck9EWghpw1Il8nbJpahKpN_utJT7Jst2HB_TDaXBvKEljdSCoo5OeCU5azEhvceJBZX0ZWy5DJ9acvJGPPMHu1SSGAVVzW75WBfI2KdVSy47Wct_yjNMkgMSmJ0E; __gads=ID=d9ef56298a116722:T=1551237969:S=ALNI_ManKOLDXQUYUvIk_3ujBg6ORNA; _gid=GA1.2.135865078.1551237968; _ga=GA1.2.88931875.1551237968; _gat=1
"; var uri = new Uri("http://www.baidu.com"); System.Net.CookieContainer cc = new System.Net.CookieContainer(); foreach (var str in cookieStr.Split(;)) cc.SetCookies(uri, str); var cookies = cc.GetCookies(uri); cc.Add(
new Cookie("a", "1") { Domain = "baidu.com" }); var strNewCookie = cc.GetCookieHeader(uri); MessageBox.Show(strNewCookie); }

c# 中 利用 CookieContainer 對 Cookie 進行序列化和反序列化校驗