当前位置: 首页>>代码示例>>C#>>正文


C# CookieContainer.GetCookieHeader方法代码示例

本文整理汇总了C#中CookieContainer.GetCookieHeader方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.GetCookieHeader方法的具体用法?C# CookieContainer.GetCookieHeader怎么用?C# CookieContainer.GetCookieHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在CookieContainer的用法示例。


在下文中一共展示了CookieContainer.GetCookieHeader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: yt

    public static SortedDictionary<int, string> yt(string targetUri)
    {
        CookieContainer cc = new CookieContainer();
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(targetUri);
        req.CookieContainer = cc;
        req.Timeout = 5000;
        req.GetResponse().Close();
        req = (HttpWebRequest)WebRequest.Create("http://www.youtube.com/get_video_info?video_id=" + Regex.Match(targetUri, "(?<=v=)[\\w-]+").Value);
        req.CookieContainer = cc;
        string _info = null;
        System.Net.WebResponse res = req.GetResponse();
        System.IO.StreamReader sr = new System.IO.StreamReader(res.GetResponseStream());
        _info = sr.ReadToEnd();
        sr.Close();
        res.Close();
        Hashtable info = new Hashtable();
        Dictionary<string, string> _tmp = new Dictionary<string, string>();
        SortedDictionary<int, string> fmtmap = new SortedDictionary<int, string>();

        foreach (string item in _info.Split('&'))
        {
            info.Add(item.Split('=')[0], Uri.UnescapeDataString(item.Split('=')[1]));
        }
        if (Convert.ToString(info["status"]) == "fail")
        {
            throw new UnauthorizedAccessException();
        }
        foreach (string item in Convert.ToString(info["url_encoded_fmt_stream_map"]).Split(','))
        {
            foreach (string a in item.Split('&'))
            {
                _tmp.Add(a.Split('=')[0], Uri.UnescapeDataString(a.Split('=')[1]));
            }
            fmtmap.Add(Convert.ToInt32(_tmp["itag"]), (_tmp["url"]) + "&signature=");
            _tmp.Clear();
        }

        req = (HttpWebRequest)WebRequest.Create("http://www.youtube.com/get_video_info?video_id=" + Regex.Match(targetUri, "(?<=v=)\\w+").Value + "&t=" + Convert.ToString(info["token"]));
        req.CookieContainer = cc;
        req.Timeout = 1500;
        req.GetResponse().Close();

        fmtmap[-2] = Convert.ToString(info["title"]);
        fmtmap[-1] = cc.GetCookieHeader(new Uri("http://www.youtube.com"));
        info.Clear();
        return fmtmap;
    }
开发者ID:kazuki0824,项目名称:Breeze-Mono,代码行数:47,代码来源:kk_movdl_csharp.cs

示例2: GetCookieHeader_Invalid

 public static void GetCookieHeader_Invalid()
 {
     CookieContainer cc = new CookieContainer();
     Assert.Throws<ArgumentNullException>(() => cc.GetCookieHeader(null));
 }
开发者ID:noahfalk,项目名称:corefx,代码行数:5,代码来源:CookieContainerTest.cs

示例3: GetCookieHeader

        private static string GetCookieHeader(Uri uri, CookieContainer cookies)
        {
            string cookieHeader = null;

            Debug.Assert(cookies != null);

            string cookieValues = cookies.GetCookieHeader(uri);
            if (!string.IsNullOrEmpty(cookieValues))
            {
                cookieHeader = string.Format(CultureInfo.InvariantCulture, "{0}: {1}", HeaderNameCookie, cookieValues);
            }

            return cookieHeader;
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:WinHttpWebSocket.cs

示例4: GetCookieHeader

        public static string GetCookieHeader(Uri uri, CookieContainer cookies)
        {
            string cookieHeader = null;

            Debug.Assert(cookies != null);

            string cookieValues = cookies.GetCookieHeader(uri);
            if (!string.IsNullOrEmpty(cookieValues))
            {
                cookieHeader = CookieHeaderNameWithColon + " " + cookieValues;                
            }

            return cookieHeader;
        }        
开发者ID:er0dr1guez,项目名称:corefx,代码行数:14,代码来源:WinHttpCookieContainerAdapter.cs

示例5: Login

    /// <summary>
    /// Logs the user in
    /// </summary>
    /// <param name="user">Reddit account username</param>
    /// <param name="pswd">Reddit account password</param>
    /// <returns>True/False depending on success of login</returns>
    public bool Login(string user, string pswd)
    {
        string postData = string.Format("api_type=json&user={0}&passwd={1}", user, pswd);
        string loginURI = m_domain + string.Format(APIPaths.login, user);
        Hashtable response = SendPOST(postData, loginURI);
        m_usr = user;

        m_errors = GetErrorsFromRedditJson(response);
        //First check for errors. Should always contain errors key.
        if (m_errors != "" )
        {
            return false;
        }
        //Only need the data segment
        Hashtable data = ((Hashtable)((Hashtable)response["json"])["data"]);
        m_modhash = data["modhash"].ToString();
        string cookieval = data["cookie"].ToString();

        redditCookie = new CookieContainer();
        Uri cookieuri = new Uri(m_domain + string.Format(APIPaths.login, user));
        redditCookie.Add(cookieuri, new Cookie("reddit_session", cookieval.Replace(",", "%2c").Replace(":", "%3A"), "/", "reddit.com"));
        jsonGet.Headers["cookie"] = redditCookie.GetCookieHeader(cookieuri);
        jsonGet.Headers["Useragent"] = m_useragent;
        m_logged_in = true;
        return true;
    }
开发者ID:ACReeser,项目名称:rKnightsOfNew,代码行数:32,代码来源:RedditAPI.cs


注:本文中的CookieContainer.GetCookieHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。