tags:

views:

28

answers:

2

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?

A: 

I don't know the answer to your question offhand but you might want to consider using HttpUnit. It makes a lot of tasks of hitting a server easy (such as authentication, providing form input, etc.). As always there are trade offs. Perhaps it would be too heavy a client for your needs... but it will allow you to maintain a session with the server.

EDIT: On second thought: Commons HttpClient might be better. I believe it is what HttpUnit uses under the hood anyway.

harschware
+2  A: 

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.

Andrew B