本文整理汇总了C#中System.Net.CookieContainer.GetType方法的典型用法代码示例。如果您正苦于以下问题:C# CookieContainer.GetType方法的具体用法?C# CookieContainer.GetType怎么用?C# CookieContainer.GetType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.CookieContainer
的用法示例。
在下文中一共展示了CookieContainer.GetType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetAllCookies
public static List<Cookie> GetAllCookies(CookieContainer cc)
{
List<Cookie> lstCookies = new List<Cookie>();
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) lstCookies.Add(c);
}
return lstCookies;
}
示例2: GetGtkByCookieSkey
/// <summary>
/// 获取cookie参数
/// </summary>
/// <param name="cc">cookie集合</param>
/// <returns></returns>
public static string GetGtkByCookieSkey(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 "";
}
示例3: UpdateCookie
/// <summary>
/// 获取cookie参数
/// </summary>
/// <param name="cc">cookie集合</param>
/// <returns></returns>
public static CookieContainer UpdateCookie(CookieContainer cc,string domain)
{
CookieContainer newcookie = 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 = domain;
c.Path = "/";
newcookie.Add(c);
}
}
return newcookie;
}
示例4: GetAllCookies
/// <summary>
/// Taken from http://stackoverflow.com/a/15991071
/// </summary>
/// <param name="cookieJar"></param>
/// <returns></returns>
public List<Cookie> GetAllCookies(CookieContainer cookieJar)
{
List<Cookie> cookieCollection = new List<Cookie>();
Hashtable table = (Hashtable)cookieJar.GetType().InvokeMember("m_domainTable",
BindingFlags.NonPublic |
BindingFlags.GetField |
BindingFlags.Instance,
null,
cookieJar,
new object[] { });
foreach (var tableKey in table.Keys)
{
String str_tableKey = (string)tableKey;
if (str_tableKey[0] == '.')
{
str_tableKey = str_tableKey.Substring(1);
}
SortedList list = (SortedList)table[tableKey].GetType().InvokeMember("m_list",
BindingFlags.NonPublic |
BindingFlags.GetField |
BindingFlags.Instance,
null,
table[tableKey],
new object[] { });
foreach (var listKey in list.Keys)
{
String url = "https://" + str_tableKey + (string)listKey;
var cookies = cookieJar.GetCookies(new Uri(url));
foreach (Cookie c in cookies)
{
cookieCollection.Add(c);
}
}
}
return cookieCollection;
}
示例5: getAllCookies
public static List<Cookie> getAllCookies(CookieContainer cc)
{
List<Cookie> lstCookies = new List<Cookie>();
Hashtable table = (Hashtable)cc.GetType().InvokeMember
("m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, cc, new object[] { });
//StringBuilder sb = new StringBuilder();
foreach (object pathList in table.Values)
{
SortedList lstCookieCol = (SortedList)pathList.GetType().InvokeMember
("m_list", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, pathList, new object[] { });
foreach (CookieCollection colCookies in lstCookieCol.Values)
{
foreach (Cookie c in colCookies)
{
lstCookies.Add(c);
//sb.AppendLine(c.Domain + ":" + c.Name + "____" + c.Value + "\r\n");
}
}
}
return lstCookies;
}
示例6: GetCookieLists
private static IEnumerable<IDictionary> GetCookieLists(CookieContainer cookieContainer)
{
Contract.Requires<ArgumentNullException>(cookieContainer != null);
Contract.Ensures(Contract.Result<IEnumerable<IDictionary>>() != null);
var containerFields = cookieContainer.GetType().GetRuntimeFields();
Contract.Assume(containerFields != null);
var domainTableField = containerFields.FirstOrDefault(x => x.Name == "m_domainTable");
Contract.Assume(domainTableField != null);
var domainTable = (IDictionary)domainTableField.GetValue(cookieContainer);
Contract.Assume(domainTable != null);
return domainTable.Values.OfType<object>().Select(domain =>
{
var domainFields = domain.GetType().GetRuntimeFields();
Contract.Assume(domainFields != null);
if (domainFields.Any() == false) return null;
var listField = domainFields.First(x => x.Name == "m_list");
return (IDictionary)listField.GetValue(domain);
});
}
示例7: GetAllCookies
/// <summary>
/// 遍历CookieContainer
/// </summary>
/// <param name="cookieContainer"></param>
/// <returns>List of cookie</returns>
public static Dictionary<string, string> GetAllCookies(CookieContainer cookieContainer)
{
Dictionary<string, string> cookies = new Dictionary<string, string>();
Hashtable table = (Hashtable)cookieContainer.GetType().InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cookieContainer, new object[] { });
foreach (string pathList in table.Keys)
{
StringBuilder _cookie = new StringBuilder();
SortedList cookieColList = (SortedList)table[pathList].GetType().InvokeMember("m_list",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField
| System.Reflection.BindingFlags.Instance, null, table[pathList], new object[] { });
foreach (CookieCollection colCookies in cookieColList.Values)
foreach (Cookie c in colCookies)
_cookie.Append(c.Name + "=" + c.Value + ";");
cookies.Add(pathList, _cookie.ToString().TrimEnd(';'));
}
return cookies;
}
示例8: saveCookies
/// <summary>
/// 打印cookies内容
/// </summary>
/// <param name="cc"></param>
public string saveCookies(CookieContainer cc)
{
List<Cookie> lstCookies = new List<Cookie>();
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) lstCookies.Add(c);
}
StringBuilder sbc = new StringBuilder();
List<Cookie> cooklist = lstCookies;
foreach (Cookie cookie in cooklist)
{
sbc.AppendFormat("{0};{1};{2};{3};{4};{5}\r\n",
cookie.Domain, cookie.Name, cookie.Path, cookie.Port,
cookie.Secure.ToString(), cookie.Value);
}
return sbc.ToString();
}
示例9: GetAllCookies
private CookieCollection GetAllCookies(CookieContainer cookieJar)
{
CookieCollection cookieCollection = new CookieCollection();
Hashtable table = (Hashtable)cookieJar.GetType().InvokeMember("m_domainTable",
BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null,
cookieJar, new object[] { });
foreach (object tableKeyObj in table.Keys)
{
string tableKey = (string)tableKeyObj;
if (tableKey[0] == '.')
tableKey = tableKey.Substring(1);
SortedList list = (SortedList)table[tableKeyObj].GetType().InvokeMember("m_list",
BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null,
table[tableKeyObj], new object[] { });
foreach (object listKeyObj in list.Keys)
{
Uri uri = new Uri(String.Format("https://{0}{1}", tableKey, listKeyObj.ToStringValue()));
cookieCollection.Add(
cookieJar.GetCookies(uri));
}
}
return cookieCollection;
}
示例10: ergodicCookie
/// <summary>
/// 遍历COOKIE返回键值对
/// </summary>
/// <param name="cookie"></param>
/// <returns></returns>
public IList<Cookie> ergodicCookie(CookieContainer cookie)
{
var listcookie = new List<Cookie>();
if (cookie.Count > 0)
{
Hashtable table = (Hashtable)cookie.GetType().InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cookie, 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)
{
listcookie.Add(c);
}
}
}
return listcookie;
}
else
{
return null;
}
}
示例11: _BugFix_CookieDomain
private void _BugFix_CookieDomain(CookieContainer cookieContainer)
{
var table = (System.Collections.Hashtable)cookieContainer.GetType().InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic |
System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance,
null,
cookieContainer,
new object[] { }
);
var keys = new System.Collections.ArrayList(table.Keys);
foreach (string keyObj in keys)
{
string key = keyObj;
if (key[0] == '.')
{
string newKey = key.Remove(0, 1);
table[newKey] = table[keyObj];
}
}
}
示例12: IterateOverCookies
private static CookieCollection IterateOverCookies(HttpWebResponse response)
{
string setCookie = response.Headers.Get("Set-Cookie");
string[] strings = setCookie.Split(';');
string name = strings.FirstOrDefault(s => s.StartsWith("name"));
string value = strings.FirstOrDefault(s => s.StartsWith("name"));
string path = strings.FirstOrDefault(s => s.ToLower().StartsWith("path="));
IEnumerable<bool> enumerable = strings.Select(s => s.StartsWith("Do"));
string domain = strings.FirstOrDefault(s => s.ToLower().StartsWith("domain="));
cookiejar.Add(new Cookie());
//=====
//Cookie cookie2 = response.Cookies[0];
//string s = response.Headers.Get("Set-Cookie");
string[] allCookies = response.Headers.AllKeys; //.Get("cookie");
foreach (string allCookie in allCookies)
{
string s1 = response.Headers.Get(allCookie);
}
//CookieCollection collection = cookieContainer.GetCookies(new Uri("http://www.futurelearn.com"));
//Cookie cookie2 = collection[0];
CookieContainer tempContainer = new CookieContainer();
foreach (Cookie cookie1 in response.Cookies)
{
tempContainer.Add(cookie1);
}
CookieCollection cookieCollection = new CookieCollection(); //testcontainer.GetCookies(new Uri("http://www.futurelearn.com"));
Hashtable table = (Hashtable)tempContainer.GetType().InvokeMember("m_domainTable",
BindingFlags.NonPublic |
BindingFlags.GetField |
BindingFlags.Instance,
null,
tempContainer,
new object[] { });
foreach (var key in table.Keys)
{
foreach (Cookie cook in tempContainer.GetCookies(new Uri(string.Format("https://{0}/", key.ToString().Trim('.')))))
{
cookieCollection.Add(cook);
Console.WriteLine("Name = {0} ; Value = {1} ; Domain = {2}", cook.Name, cook.Value, cook.Domain);
}
}
//=====
return cookieCollection;
}
示例13: GetAllCookies
public static List<Cookie> GetAllCookies(CookieContainer cc)
{
List<Cookie> list = new List<Cookie>();
Hashtable hashtable = (Hashtable)cc.GetType().InvokeMember("m_domainTable", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, cc, new object[0]);
StringBuilder stringBuilder = new StringBuilder();
foreach (object current in hashtable.Values)
{
SortedList sortedList = (SortedList)current.GetType().InvokeMember("m_list", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.GetField, null, current, new object[0]);
foreach (CookieCollection cookieCollection in sortedList.Values)
{
foreach (Cookie cookie in cookieCollection)
{
list.Add(cookie);
stringBuilder.AppendLine(string.Concat(new string[]
{
cookie.Domain,
":",
cookie.Name,
"____",
cookie.Value,
"\r\n"
}));
}
}
}
return list;
}
示例14: GetAllCookiesToString
public static string GetAllCookiesToString(CookieContainer cc)
{
var tmpCookie = string.Empty;
var table =
(Hashtable)
cc.GetType()
.InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });
tmpCookie = (from object pathList in table.Values
select
(SortedList)
pathList.GetType()
.InvokeMember("m_list",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, pathList, new object[] { })
into lstCookieCol
from CookieCollection colCookies in lstCookieCol.Values
from Cookie c in colCookies
select c).Aggregate(tmpCookie, (current, c) => current + (" " + c.ToString() + ";"));
if (tmpCookie.Length > 0)
tmpCookie = tmpCookie.Substring(0, tmpCookie.Length - 1);
return tmpCookie;
}
示例15: CookieToString
/// <summary>
/// 将CookieContainer转换为string类型
/// </summary>
/// <param name="cc"></param>
/// <returns></returns>
public string CookieToString(CookieContainer cc)
{
System.Collections.Generic.List<Cookie> lstCookies = new System.Collections.Generic.List<Cookie>();
Hashtable table = (Hashtable)cc.GetType().InvokeMember("m_domainTable",
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.GetField |
System.Reflection.BindingFlags.Instance, null, cc, new object[] { });
StringBuilder sb = new StringBuilder();
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)
{
sb.Append(c.Name).Append("=").Append(c.Value).Append(";");
}
}
return sb.ToString();
}