Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to submit a form in a web

807580Sep 11 2010 — edited Sep 13 2010
Hi, it's my first post in this forum and it's for asking a very rough problem.
I want to log in a web which uses a form to authenticate. The page is: https://cv2008.uab.cat. I want that my program in java logs in and retrieves information from it (e.g. downloading a file). I've been studying the form and it uses POST method and requires to fill the username and password fields. Moreover I've found something interesting in the form:
<input type="hidden" name="lt" value="_c23CA00BA-41D7-8934-6F3E-D754BD70ECBE_kAAFD1C38-B06B-2F6E-776D-92949E17286F" />
<input type="hidden" name="_eventId" value="submit" />
but I don't know what to do with it.
Well, about the app, I've been trying to use common httpclient and the.net libs but I couldn't log in.
Here is my last try:
import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.NameValuePair;

import org.apache.commons.httpclient.methods.PostMethod;

public class HttpClientTutorial {
	
	
	
    public static void main(String[] args){
    	HttpClient client = new HttpClient();      
    	String response = null;
    	PostMethod authPost = new PostMethod("https://sac.uab.cat/login?service=https://cv2008.uab.cat/home/");
    	NameValuePair[] data = { 
    	          new NameValuePair("username", "MY_USER"), 
    	          new NameValuePair("password", "MY_PASS"),
    	          new NameValuePair("lt", "_c23CA00BA-41D7-8934-6F3E-D754BD70ECBE_kAAFD1C38-B06B-2F6E-776D-92949E17286F"),  
    	          new NameValuePair("_eventId", "submit"),  
    	          new NameValuePair("submit","submit") 
    	                   
    	         }; 
    	authPost.setRequestBody(data);
    	try {
    		client.executeMethod(authPost);  
    		response = authPost.getResponseBodyAsString();
    		System.out.println(authPost.getStatusCode());
    	}
    	catch(Exception e)
    	{
    		System.out.println("Error");
    	}
    	    	
    	authPost.releaseConnection();
    	System.out.println(response);
    }
}
I'd appreciate any help, thank you!

Kits
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 11 2010
Added on Sep 11 2010
8 comments
191 views