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

推荐订阅源

博客园_首页
Y
Y Combinator Blog
Engineering at Meta
Engineering at Meta
D
Docker
GbyAI
GbyAI
aimingoo的专栏
aimingoo的专栏
大猫的无限游戏
大猫的无限游戏
腾讯CDC
P
Proofpoint News Feed
A
About on SuperTechFans
WordPress大学
WordPress大学
Stack Overflow Blog
Stack Overflow Blog
Google DeepMind News
Google DeepMind News
C
Check Point Blog
Microsoft Security Blog
Microsoft Security Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
L
LangChain Blog
MyScale Blog
MyScale Blog
博客园 - 三生石上(FineUI控件)
Hugging Face - Blog
Hugging Face - Blog
Microsoft Azure Blog
Microsoft Azure Blog
N
Netflix TechBlog - Medium
G
Google Developers Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

博客园 - 亲,注意身体

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)  评论()    收藏  举报