title: Java get Session Cookies
body: <p><a href="https://stackoverflow.com/questions/5921056/how-to-get-cookies-with-java">Getting header fields from a URLConnection</a> doesn't get session cookies for me.</p>
  
  <p>When I use <code>CookieManager</code> I can get session cookies from a URL:</p>
  
  <pre><code>CookieManager manager = new CookieManager();
  manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
  CookieHandler.setDefault(manager);
  
  URLConnection con = url.openConnection();
  con.getContent();
  
  CookieStore cookieJar = manager.getCookieStore();
  List&lt;HttpCookie&gt; cookies = cookieJar.getCookies();
  </code></pre>
  
  <p>This is fine, but I need to send a POST request. So I am writing to the URLConnection's output stream. My question is how to get the session cookies after sending the POST request.</p>