Skip to content

Instantly share code, notes, and snippets.

@stephenpatten
Created November 16, 2017 19:45
Show Gist options
  • Select an option

  • Save stephenpatten/603e297865d879a8c0c15b47052f1f41 to your computer and use it in GitHub Desktop.

Select an option

Save stephenpatten/603e297865d879a8c0c15b47052f1f41 to your computer and use it in GitHub Desktop.
HttpClient Cookies
CookieContainer cookies = new CookieContainer();
HttpClientHandler handler = new HttpClientHandler();
handler.CookieContainer = cookies;
HttpClient client = new HttpClient(handler);
HttpResponseMessage response = client.GetAsync("http://google.com").Result;
Uri uri = new Uri("http://google.com");
IEnumerable<Cookie> responseCookies = cookies.GetCookies(uri).Cast<Cookie>();
foreach (Cookie cookie in responseCookies)
Console.WriteLine(cookie.Name + ": " + cookie.Value);
Console.ReadLine();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment