title: HttpClient 4.x: how to retain cookies across multiple requests?
body: <p>I need to use Apache HttpClient (4.x) to make 3 consecutive web calls and essentially log me into my app programmatically:</p>
  
  <ol>
  <li>An HTTP GET to a login page (<code>http://myapp01.example.com</code>)</li>
  <li>The server will respond to this GET with a response cookie "<code>JSESSIONID</code>"</li>
  <li>An HTTP POST to the same page (using the same <code>JSESSIONID</code> as a request cookie)</li>
  <li>The server now authenticates me and validates the <code>JSESSIONID</code>.</li>
  <li>An HTTP GET to a different page under the same domain (<code>http://myapp01.example.com/fizz</code>), again using the same <code>JSESSIONID</code> as a request cookie</li>
  </ol>
  
  <p>The first GET's response will contain a cookie named <code>JSESSIONID</code>. The POST will then log me in to the server (sending username and password data in the POST request body). This POST will also send (<code>Set-Cookie</code>) the <code>JSESSIONID</code> cookie received from the first GET. If my logins are successful, the <code>JSESSIONID</code> will now be authenticated, and I am logged in. I can then make the 2nd GET call (still using the same <code>JSESSIONID</code>) to <code>/fizz</code> which is ordinarily an authenticated URL.</p>
  
  <p>Can this be done in HttpClient 4? I see there is a method <code>HttpClient.getCookieStore()</code>. but this seems to only store cookies per GET/POST/PUT/etc.</p>
  
  <p><strong>Any ideas as to how I can get this holding cookies across multiple requests, such that any cookies returned by the server are then added to subsequent requests?</strong></p>