Re: How to login to the webpage with httpclient API
Hi RGB,
Thank you very much for your answer, I was almost lost hope that no
one will reply me.
On the question, Is FRONT_PAGE = siteName + "redirect.php"?
It is actually the address of the login page. Is it alright?
public static void main(String[] args) throws Exception
{
HttpClient client = new HttpClient();
PostMethod authpost = new PostMethod(FRONT_PAGE);
NameValuePair usr = new NameValuePair("login_username",
username);
NameValuePair psw = new NameValuePair("secretkey", password);
NameValuePair autodetect = new
NameValuePair("js_autodetect_results", "0");
NameValuePair login = new NameValuePair("just_logged_in",
"1");
authpost.setRequestBody(new NameValuePair[] {usr, psw,
autodetect, login});
client.executeMethod(authpost);
System.out.println("Login form post: " +
authpost.getStatusLine().toString());
System.out.println(authpost.getResponseBodyAsString());
authpost.releaseConnection();
}
I put the two hidden field in, I was expecting that the
getResponseBodyAsString will return the page after login, but it
return the page at the login page, doesn't seems to send request to
the server? am I do it right?
I am installing the WireShark, I will check it now, will put the
result back here.
For more information, the page is a squirrelmail which provide by my
company to allows us to check email there.
The reason I am doing this is that there are many email (same format)
contains data in it, currently, I am doing it manually by opening the
email and convert it to excel, I would like to write an application to
automate the process.
I really appreciate your help.
Best Regard
Ferdinand Ng