本文整理汇总了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;
}
示例2: GetCookieHeader_Invalid
public static void GetCookieHeader_Invalid()
{
CookieContainer cc = new CookieContainer();
Assert.Throws<ArgumentNullException>(() => cc.GetCookieHeader(null));
}
示例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;
}
示例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;
}
示例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;
}