Как бы так с наименьшими усилиями конвертнуть System.Net.CookieContainer в project.Profile.CookieContainer (потом выполнить нужную работу), после чего конвертнуть в обратную сторону?
Спасибо. Нет не пробовал - познаний нехватает, можешь набросать пример?а просто преобразованием типов не пробовал?
Тему пролистал, видимо не внимательно, посмотрю внимательнее. Спасибо!тут, посмотрите, в одну сторону показал как
var cookieContainer = httpClient.HttpHandler.CookieContainer.GetCookies(new Uri("https://"));
//2.1 Export to zpprofile
foreach (Cookie item in cookieContainer) {
var cookie = project.Profile.CookieContainer.Create(
item.Domain,
item.Path,
item.Name,
item.Value,
item.Expires,
item.Secure,
item.HttpOnly,
item.Discard,
"Unspecified Medium",
null
);
project.Profile.CookieContainer.Add(cookie);
}
//2.2. Export to string
//var cookie = new StringBuilder();
//foreach (Cookie item in cookieContainer) {
// cookie.Append($"{item.Name}={item.Value}; ");
//}
хватает. Такое делал 100%познаний нехватает
long a = 1;
int b = (int) a;
Посмотреть вложение 77297
C#:var cookieContainer = httpClient.HttpHandler.CookieContainer.GetCookies(new Uri("https://")); //2.1 Export to zpprofile foreach (Cookie item in cookieContainer) { var cookie = project.Profile.CookieContainer.Create( item.Domain, item.Path, item.Name, item.Value, item.Expires, item.Secure, item.HttpOnly, item.Discard, "Unspecified Medium", null ); project.Profile.CookieContainer.Add(cookie); } //2.2. Export to string //var cookie = new StringBuilder(); //foreach (Cookie item in cookieContainer) { // cookie.Append($"{item.Name}={item.Value}; "); //}
System.Net.CookieContainer сс = new System.Net.CookieContainer();
// ----- где-то тут запросы получающие нужные куки...
Hashtable table = (Hashtable) cc.GetType().InvokeMember( "m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, cc, new object[] { });
foreach(var key in table.Keys) {
var item = table[key];
var items = (ICollection)item.GetType().GetProperty("Values").GetGetMethod().Invoke(item, null);
foreach(CookieCollection ccc in items) {
foreach(Cookie item1 in ccc) {
var cookie = project.Profile.CookieContainer.Create(
item1.Domain,
item1.Path,
item1.Name,
item1.Value,
item1.Expires,
item1.Secure,
item1.HttpOnly,
item1.Discard,
"Unspecified Medium", // ??? Unspecified Medium - за что отвечает - что это?
null // // ??? Unspecified Medium - за что отвечает - что это?
);
project.Profile.CookieContainer.Add(cookie);
}
}
}
Делал, это точно, но как это должно срабатывать с разными этими контейнерами хз, из-за чего даже побоялся пробовать...хватает. Такое делал 100%
"Unspecified Medium", // ??? Unspecified Medium - за что отвечает - что это?
null // // ??? Unspecified Medium - за что отвечает - что это?
var cookieContainer = new System.Net.CookieContainer();
var httpClientHandler = new HttpClientHandler()
{
CookieContainer = cookieContainer,
UseCookies = true
};
string result = null;
using(var httpClient = new HttpClient(httpClientHandler))
{
var responseTask = httpClient.GetAsync("http://google.com");
result = responseTask.Result.Content.ReadAsStringAsync().Result;
}
Hashtable table = (Hashtable) cookieContainer.GetType().InvokeMember( "m_domainTable", BindingFlags.NonPublic | BindingFlags.GetField | BindingFlags.Instance, null, cookieContainer, new object[] { });
foreach(var key in table.Keys) {
var item = table[key];
var items = (ICollection)item.GetType().GetProperty("Values").GetGetMethod().Invoke(item, null);
foreach(System.Net.CookieCollection ccc in items) {
foreach(System.Net.Cookie item1 in ccc) {
var cookie = project.Profile.CookieContainer.Create(
item1.Domain,
item1.Path,
item1.Name,
item1.Value,
item1.Expires,
item1.Secure,
item1.HttpOnly,
item1.Discard,
"Unspecified Medium",
null
);
project.Profile.CookieContainer.Add(cookie);
}
}
}
return result;



