I\'ve got the following code that works successfully. I can\'t figure out how to get the cookie out of the response. My goal is that I want to be able to set cookies in th
You can easily get a cookie value with the given URL.
private async Task GetCookieValue(string url, string cookieName)
{
var cookieContainer = new CookieContainer();
var uri = new Uri(url);
using (var httpClientHandler = new HttpClientHandler
{
CookieContainer = cookieContainer
})
{
using (var httpClient = new HttpClient(httpClientHandler))
{
await httpClient.GetAsync(uri);
var cookie = cookieContainer.GetCookies(uri).Cast().FirstOrDefault(x => x.Name == cookieName);
return cookie?.Value;
}
}
}