Answer the question
In order to leave comments, you need to log in
How to convert the data received in the form of cookie text to the Cookie type?
Hello everyone!
I get cookie data from the request like this
System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();
System.Net.Http.HttpResponseMessage response = await client.GetAsync("https://www.igromania.ru/");
response.EnsureSuccessStatusCode();
string responseBody = await response.Content.ReadAsStringAsync();
System.Net.Http.Headers.HttpResponseHeaders hd = response.Headers;
System.Net.CookieContainer cookieBox = new System.Net.CookieContainer();
if (hd.Contains("Set-Cookie"))
{
var setCookieHeaders = hd.GetValues("Set-Cookie");
foreach(var cooks in setCookieHeaders)
{
cookieBox.Add();
Console.WriteLine(cooks);
}
Answer the question
In order to leave comments, you need to log in
The question was born!
Let's look at MDN again .
foreach(var cookieLine insetCookieHeaders)
{
// Допустим, что нам нужна только первая часть куки, без всяких HttpOnly и Expires
var cookie = cookieLine.Split(';')[0];
cookieBox.Add(cookie); // Хз, что за cookieBox. Предполагаю, что это List<string>
Console.WriteLine(cookie);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question