Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

posting a form automatically

 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 6920
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13058
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic