29 lines
1.1 KiB
C#
29 lines
1.1 KiB
C#
using System.Collections;
|
|
using System.Linq;
|
|
using System.Net;
|
|
using System.Reflection;
|
|
|
|
namespace NetDisk
|
|
{
|
|
public static class Extension
|
|
{
|
|
public static CookieCollection GetAllCookies(this CookieContainer container)
|
|
{
|
|
var allCookies = new CookieCollection();
|
|
var domainTableField = container.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).FirstOrDefault(x => x.Name == "m_domainTable");
|
|
var domains = (IDictionary)domainTableField.GetValue(container);
|
|
|
|
foreach (var val in domains.Values)
|
|
{
|
|
var type = val.GetType().GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static).First(x => x.Name == "m_list");
|
|
var values = (IDictionary)type.GetValue(val);
|
|
foreach (CookieCollection cookies in values.Values)
|
|
{
|
|
allCookies.Add(cookies);
|
|
}
|
|
}
|
|
return allCookies;
|
|
}
|
|
}
|
|
}
|