Cookiecontainer в переменную в с#

TheBoss

Client
Регистрация
30.03.2015
Сообщения
529
Благодарностей
193
Баллы
43
Привет! Подскажите код, как Cookiecontainer прописать в переменную для C# после запроса ниже. Или в целом вот у меня сейчас есть куки в Cookiecontainer, как мне без переходов на страницу, записать в переменную, то что уже сейчас есть в Cookiecontainer?


string url = "https://tel.mail.ru/message/"+(project.Variables["id_massage"].Value);
string proxy = project.Variables["proxy"].Value;
string encoding = "UTF-8"; //Кодировка
int timeout = 10000; //Таймаут запроса
string cookies = project.Variables["cookies"].Value; //Куки
string userAgent = project.Variables["useragent"].Value; //Юзерагент
bool useRedirect = true; //Редеректить ли автоматически запрос при необходимости. Например, когда ответ от сервера с кодом 302 в браузере вас автоматом перенаправит по другой ссылке.
int maxRedirectCount = 5; //Максимальное количество редиректов. Для использования UseRedirect должен быть включен.
string[] additionalHeaders = {
"Accept-Language: ru-RU,ru;q=0.8,en-US;q=0.5,en;q=0.3",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Connection: keep-alive"}; // Дополнительные заголовки.
var response = ZennoPoster.HttpGet(url, proxy, encoding, ResponceType.HeaderAndBody, timeout, cookies, userAgent, useRedirect, maxRedirectCount, additionalHeaders);
project.Variables["get_info"].Value = response;

За ранее спасибо!
 
  • Спасибо
Реакции: Radzhab

swiniks

Client
Регистрация
19.02.2015
Сообщения
244
Благодарностей
171
Баллы
43
Получить Сookie в переменную из CookieContainer:
return Encoding.UTF8.GetString(project.Profile.CookieContainer.Export());
GET Метод:

Get(String) Method:
// http request
ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
// get cookie items
var items = project.Profile.CookieContainer.Get("zennolab.com");
// output to log info of cookie item
foreach(var item in items)
{
    project.SendInfoToLog(item.Name + " = " + item.Value);
}
Get(String,String) Method:
// http request
ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
// get cookie items
var items = project.Profile.CookieContainer.Get("zennolab.com", "/");
// output to log info of cookie item
foreach(var item in items)
{
    project.SendInfoToLog(item.Name + " = " + item.Value);
}
Get(String,String,Boolean) Method:
// http request
ZennoPoster.HTTP.Request(InterfacesLibrary.Enums.Http.HttpMethod.GET, "https://zennolab.com", cookieContainer: project.Profile.CookieContainer);
// get cookie items
var items = project.Profile.CookieContainer.Get("zennolab.com", "/", false);
// output to log info of cookie item
foreach(var item in items)
{
    project.SendInfoToLog(item.Name + " = " + item.Value);
}
 

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)