I don't have a clean example, but I did code a small rough snippet to try it to make sure it worked before responding earlier. I attached it, but mainly for the purposes of showing how I grabbed the cookies and included them in a subsequent request.
I just saved any entries that showed up in the "Set-Cookie" header, making sure to handle multiple entries, and then included them in the "Cookie" header in subsequent requests. The code would need to be a bit more robust to handle different scenarios though...for example, if your session times out you might need to handle that situation and provide your credentials to create a new session.
Alternatively, you could provide your credentials along with the cookies with each request. The credentials would be ignored unless the session is invalid, and then a new session with be created without a 401 being returned. (In this case, you would be given a new session in the Set-Cookie header).