title: Read cookie in WPF application
body: <p>in a wpf application I have to call an external rest service which returns a cookie with session id in it. In all subsequent calls I have to send session id in cookie otherwise it does not return any data. </p>
  
  <p>So how can I retrieve the cookie in wpf code behind class?</p>
  
  <pre><code>CookieContainer cookies = new CookieContainer();
  HttpClientHandler handler = new HttpClientHandler();
  handler.CookieContainer = cookies;
  
  HttpClient client = new HttpClient(handler);
  var domain = EndPoint;
  HttpResponseMessage response2 = client.PostAsync(domain, new StringContent(parameters)).Result;
  
  Uri uri = new Uri(domain);
  IEnumerable&lt;Cookie&gt; responseCookies = cookies.GetCookies(uri).Cast&lt;Cookie&gt;();
  var cookieWithId = responseCookies.Single(o =&gt; o.Name == "JESSSIONID");
  </code></pre>
  
  <p>where EndPoint has <a href="http://mydomain.com:38080/workshop/" rel="nofollow">http://mydomain.com:38080/workshop/</a> and parameters has rest/login?username=usr&amp;password=pwd</p>