• c# CookieContainer Cookie丢失bug、跨域问题等解决方案


     

    //修改域
    public static CookieContainer InitCookie(CookieContainer cc)
    {
    CookieContainer coo = new CookieContainer();
    Hashtable table = (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)
    {
    SortedList lstCookieCol = (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)
    {
    c.Domain = ".qq.com";
    coo.Add(c);
    
    }
    }
    return coo;
    }
     
    //提取Cookie值
      public static string GetValueByCookieName(string key, CookieContainer cc)
            {
                Hashtable table = (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)
                {
                    SortedList lstCookieCol = (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)
                        {
                            if (c.Name.ToLower() == key)
                            {
                                return c.Value;
                            }
                        }
                }
                return "";
            }
     
    

      

  • 相关阅读:
    freebsd安装mysql
    freebsd安装ports
    分布式拒绝服务攻击
    如何用命令获知当前是一年中的第多少周和今天是周几
    freebsd软件包下载地址
    mod_wsgi的两种模式
    freebsd中/etc/rc.conf配置文件导致不能启动的问题
    进程ID[PID(Process ID)]与端口号[(Port ID)]的联系
    Java EE之HttpServletRequest
    Chrome之控制台使用【转载】
  • 原文地址:https://www.cnblogs.com/chengulv/p/2828068.html
Copyright © 2020-2023  润新知