I'm trying to POST to a login form over URLConnection, then get two cookies I need to browse the website after a successful login. The actual POST data is accepted and the server logs me in, however the response instead of html containing cookies is "301 Moved Permanently". I suppose this is a redirect?

How do I follow the redirect, and how do I get the cookies?

Thank you!