I got some sample code from the net here:
http://www.javadb.com/sending-a-post-request-with-parameters-from-a-java-class
That works fine. It sets the relevant headers in the response. However, what if I wanted to visit another url on the same site with those headers? If I create another URL object the session is lost. How do I maintain the session?
You’re going at a pretty low level, unless that’s intentional, you might want to consider using a library such as Apache Commons HttpClient, which will handle cookie management for you.