C
C
CityzenUNDEAD2020-11-14 18:50:03
Parsing
CityzenUNDEAD, 2020-11-14 18:50:03

How to get the cookie value when making a request to the site?

Hello everyone!
You need to get the cookie value that is returned when requesting the site.
For the request I use the httpclient class.

var client = new System.Net.Http.HttpClient();
var response = await client.GetAsync("https://www.igromania.ru/");
response.EnsureSuccessStatusCode();
var responseBody = await response.Content.ReadAsStringAsync();
var headers = response.Headers;

It turns out that the headers are now in the variable headers. How do you get cookies out of there?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vasily Bannikov, 2020-11-14
@vabka

var setCookieHeaders = headers.Contains("Set-Cookie") 
                               ? headers.GetValues("Set-Cookie")
                               : Array.Empty<string>();

MDN about Set-Cookie
Documentation on HttpResponseHeaders.GetValues

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question