document.cookie="id=250;expires=Wed, 24 Nov 2010 03:19:02 UTC;path=/";这是某段js写入了一个cookies,暂时命名为xxx.js比如我用HttpWebRequest去访问www.xxx.com,然后用了CookiesContainer存储此访问的cookies
www.xxx.com首页里包含了<script src="xxx.js"></script>
也就是说,这句话执行了,而通过HttpWebRequest获取的cookies里面并没有id=250这么一个cookies我用httpAnanlyzer和fidder也同样抓不到id = 250这么个cookies请问,我用winform程序如何去做?p.s.我不用webbrowser控件。

解决方案 »

  1.   


    /// <summary>
    /// 读取Cookies
    /// </summary>
    /// <param name="str"></param>
    /// <returns></returns>
    public string GetCookies(string key)
    {
        if (System.Web.HttpContext.Current.Request.Cookies[key] != null)
        {
            string _cstr = System.Web.HttpContext.Current.Request.Cookies[key].Value.ToString();
            Encoding stre = Encoding.GetEncoding("UTF-8");
            return System.Web.HttpUtility.UrlDecode(_cstr, stre);
        }
        else
        {
            return string.Empty;
        }
    }//获取cookie
    string referer = GetCookies("fromUrl");//写cookies
    function setCookie(name,value)
    {
       document.cookie = name   "="  escape (value)  ";path=/";  //设置的cookie关闭浏览即失效
    }