aspose file tools*
The moose likes Servlets and the fly likes posting a form automatically Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "posting a form automatically" Watch "posting a form automatically" New topic
Author

posting a form automatically

Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
I'm trying to submit a form with username and password to automate the login process but I'm stuck... I need to return the new URL after the form has been submitted. I've tried the following and don't get any errors but it doesn't return anything.
URL url = new URL("https://manager.verisign.com/login/loginaction.cfm");
HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setFollowRedirects(true);
connection.addRequestProperty("partnerid","partnerid");
connection.addRequestProperty("login","login");
connection.addRequestProperty("password","password");
connection.connect();
Any help would be appreciated.
Thanks,
Dave
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
With addRequestProperty you are creating request header lines - not the same as what the servlet request contains when a form is submitted - which a program retrieves with getParameter("useid") - etc.
With a GET request, the parameters come as part of the URL (you can see this in the URL for this page). With a POST request, the parameters come in the body of the request (after the headers) as name=value pairs
Bill
Dave Bosky
Ranch Hand

Joined: Dec 16, 2003
Posts: 72
So to automatically submit a prepopulated form to a website I need to do what? Do you have a simple example? Which classes do I need to use to accomplish this task? I'm pretty frustrated... I've been looking for an example of which classes to use and have come up dry all day long.
Thanks Again,
Dave
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Whenevr I need to "remote control" another website I use HttpUnit it's positioned as a web testing tool, but is actually very good at controlling web applications, building and sending data, and processing the replies.
One of my recent articles in The JavaRanch Journal covers a simple introduction how to do this.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12806
    
    5
Well since Frank has mentioned HttpUnit, I am obligated to mention the HttpClient toolkit - part of the Jakarta Commons project. which I have used to mimic form submission when load testing servlets.
Bill
 
Consider Paul's rocket mass heater.
 
subject: posting a form automatically