惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Google DeepMind News
Google DeepMind News
博客园 - 聂微东
Microsoft Azure Blog
Microsoft Azure Blog
V
Visual Studio Blog
IT之家
IT之家
博客园 - 【当耐特】
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
B
Blog
爱范儿
爱范儿
阮一峰的网络日志
阮一峰的网络日志
云风的 BLOG
云风的 BLOG
Vercel News
Vercel News
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
H
Hackread – Cybersecurity News, Data Breaches, AI and More
H
Help Net Security
J
Java Code Geeks
aimingoo的专栏
aimingoo的专栏
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
B
Blog RSS Feed
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research

博客园 - 亲,注意身体

magento 数据清理 magento top menu edit magento sitemap cms page remove home and generate sitemap error magento toplink blank li magento 语言包 magetno awblog auto generate title id, js replace magento moneybooker 操作 JS 正则 js 数组 组合(转) magento checkout require moneybooker api/mqi query magento 记录蜘蛛爬行日志 magento moneybooker redirect 添加信任站点 bat 设置信任站点等级 moneybooker api 文档 magento htaccess Navicat 注册码,序列号 magento 修改订单号 Magento 删除所有订单 适于于1.4+
CookieConter 转换为string
亲,注意身体 · 2012-11-09 · via 博客园 - 亲,注意身体

public static string GetCookieString(System.Net.CookieContainer cc)
    {
        string str = "";
        List<Cookie> listcookie = GetAllCookies(cc);
        foreach (Cookie c in listcookie)
        {
            string name = c.Name;
            string value = c.Value;
            string domain = c.Domain;
            str += name + "=" + value + ";domain=" + domain + "\n";
        }

        return str;
    }
    /// <summary>
    /// 获取CookieContainer中对象
    /// </summary>
    /// <param name="cc"></param>
    /// <returns></returns>
    private static List<Cookie> GetAllCookies(CookieContainer cc)
    {
        if (cc == null)
        {
            return new List<Cookie>();
        }
        List<Cookie> lstCookies = new List<Cookie>();

        System.Collections.Hashtable table = (System.Collections.Hashtable)cc.GetType().InvokeMember("m_domainTable", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, cc, new object[] { });

        foreach (object pathList in table.Values)
        {
            System.Collections.SortedList lstCookieCol = (System.Collections.SortedList)pathList.GetType().InvokeMember("m_list", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField | System.Reflection.BindingFlags.Instance, null, pathList, new object[] { });
            foreach (CookieCollection colCookies in lstCookieCol.Values)
                foreach (Cookie c in colCookies) lstCookies.Add(c);
        }

        return lstCookies;
    }

posted on 2012-11-09 14:54  亲,注意身体  阅读(899)  评论()    收藏  举报