本文整理汇总了C#中System.Net.CookieContainer.List方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.List方法的具体用法?C# CookieContainer.List怎么用?C# CookieContainer.List使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.CookieContainer
的用法示例。
在下文中一共展示了CookieContainer.List方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Login
public override bool Login()
{
CookieContainer cookieJar = new CookieContainer();
_client = new CookieAwareWebClient(cookieJar);
_client.Referer = HOME_URL;
// the website sets some cookie that is needed for login
string response = _client.DownloadString(HOME_URL);
Cookie tokenCookie = cookieJar.List().FirstOrDefault(c => c.Name == "csrftoken");
StringBuilder postData = new StringBuilder();
postData.Append("email=" + HttpUtility.UrlEncode(Username) + "&");
postData.Append("password=" + HttpUtility.UrlEncode(Password) + "&");
postData.Append("remember=False=");
// the csrf token is sent in the hader
_client.Headers.Add("User-Agent", USER_AGENT);
_client.Headers.Add("Accept", "application/json, text/javascript, */*; q=0.01");
_client.Headers.Add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
_client.Headers.Add("Referer", HOME_URL);
_client.Headers.Add("X-Requested-With", "XMLHttpRequest");
_client.Headers.Add("X-CSRFToken", tokenCookie.Value);
response = _client.UploadString(LOGIN_API, postData.ToString());
JObject jObject = JObject.Parse(response);
JToken jToken = jObject.GetValue("success");
if (!jToken.Value<bool>())
{
//The query returned false, either not authenticated or forbiddent (403)
Console.WriteLine("Wrong email or password logging into Edx.");
return false;
}
//Now get the goods (cookies should be set!)
return true;
}