N
ngxfer001
Hi Experts,
I am new the httpclient API. I am trying to access a webmail and grap
the email from the webmail. I found out that httpclient API can do
that, the web page login page is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<!-- � -->
<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />
<title>SquirrelMail - ãƒã‚°ã‚¤ãƒ³</title><script language="JavaScript"
type="text/javascript">
<!--
function squirrelmail_loginpage_onload() {
document.forms[0].js_autodetect_results.value = '1';
var textElements = 0;
for (i = 0; i < document.forms[0].elements.length; i++) {
if (document.forms[0].elements.type == "text" ||
document.forms[0].elements.type == "password") {
textElements++;
if (textElements == 1) {
document.forms[0].elements.focus();
break;
}
}
}
}
// -->
</script>
<!--[if IE 6]>
<style type="text/css">
/* avoid stupid IE6 bug with frames and scrollbars */
body {
width: expression(document.documentElement.clientWidth - 30);
}
</style>
<![endif]-->
</head>
<body text="#000000" bgcolor="#ffffff" link="#0000cc" vlink="#0000cc"
alink="#0000cc" onLoad="squirrelmail_loginpage_onload();">
<form action="redirect.php" method="post">
<table bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0"
width="100%"><tr><td align="center"><center><img src="../images/
sm_logo.png" alt="SquirrelMail ãƒã‚´" width="308" height="111" /><br />
<small>SquirrelMail ãƒãƒ¼ã‚¸ãƒ§ãƒ³ 1.4.8<br />
SquirrelMail プãƒã‚¸ã‚§ã‚¯ãƒˆã®ãƒãƒ¼ãƒ ã«ã‚ˆã£ã¦<br /></small>
<table bgcolor="#ffffff" border="0" width="350"><tr><td
bgcolor="#dcdcdc" align="center"><b>SquirrelMail ãƒã‚°ã‚¤ãƒ³</b>
</td>
</tr>
<tr><td bgcolor="#ffffff" align="left">
<table bgcolor="#ffffff" align="center" border="0"
width="100%"><tr><td align="right" width="30%">ãƒã‚°ã‚¤ãƒ³å:</td>
<td align="left" width="*"><input type="text" name="login_username"
value="" />
</td>
</tr>
<tr><td align="right" width="30%">パスワード:</td>
<td align="left" width="*"><input type="password" name="secretkey" />
<input type="hidden" name="js_autodetect_results" value="0" />
<input type="hidden" name="just_logged_in" value="1" />
</td>
</tr>
</table>
</td>
</tr>
<tr><td align="left"><center><input type="submit" value="ãƒã‚°ã‚¤ãƒ³" />
</center></td>
</tr>
</table>
</center></td>
</tr>
</table>
</form>
</body></html>
What I want to do is to put the username and password in the webpage
and click submit
My code is as follows:
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);
authpost.setRequestBody(new NameValuePair[] {usr, psw,
action});
client.executeMethod(authpost);
System.out.println("Login form post: " +
authpost.getStatusLine().toString());
System.out.println(authpost.getResponseBodyAsString());
authpost.releaseConnection();
}
I know that this doesn't work because of the following question?
1) How to click the button with httpclient API?
2) I feel that the javascript will affect my login?
Can you please help me, I try to find in google for 2 days and try
many example and it doesn't work.
Thank you for reading this post.
best Regards
Ferdinand Ng
I am new the httpclient API. I am trying to access a webmail and grap
the email from the webmail. I found out that httpclient API can do
that, the web page login page is as follows:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta name="robots" content="noindex,nofollow">
<!-- � -->
<meta http-equiv="Content-type" content="text/html; charset=euc-jp" />
<title>SquirrelMail - ãƒã‚°ã‚¤ãƒ³</title><script language="JavaScript"
type="text/javascript">
<!--
function squirrelmail_loginpage_onload() {
document.forms[0].js_autodetect_results.value = '1';
var textElements = 0;
for (i = 0; i < document.forms[0].elements.length; i++) {
if (document.forms[0].elements.type == "text" ||
document.forms[0].elements.type == "password") {
textElements++;
if (textElements == 1) {
document.forms[0].elements.focus();
break;
}
}
}
}
// -->
</script>
<!--[if IE 6]>
<style type="text/css">
/* avoid stupid IE6 bug with frames and scrollbars */
body {
width: expression(document.documentElement.clientWidth - 30);
}
</style>
<![endif]-->
</head>
<body text="#000000" bgcolor="#ffffff" link="#0000cc" vlink="#0000cc"
alink="#0000cc" onLoad="squirrelmail_loginpage_onload();">
<form action="redirect.php" method="post">
<table bgcolor="#ffffff" border="0" cellspacing="0" cellpadding="0"
width="100%"><tr><td align="center"><center><img src="../images/
sm_logo.png" alt="SquirrelMail ãƒã‚´" width="308" height="111" /><br />
<small>SquirrelMail ãƒãƒ¼ã‚¸ãƒ§ãƒ³ 1.4.8<br />
SquirrelMail プãƒã‚¸ã‚§ã‚¯ãƒˆã®ãƒãƒ¼ãƒ ã«ã‚ˆã£ã¦<br /></small>
<table bgcolor="#ffffff" border="0" width="350"><tr><td
bgcolor="#dcdcdc" align="center"><b>SquirrelMail ãƒã‚°ã‚¤ãƒ³</b>
</td>
</tr>
<tr><td bgcolor="#ffffff" align="left">
<table bgcolor="#ffffff" align="center" border="0"
width="100%"><tr><td align="right" width="30%">ãƒã‚°ã‚¤ãƒ³å:</td>
<td align="left" width="*"><input type="text" name="login_username"
value="" />
</td>
</tr>
<tr><td align="right" width="30%">パスワード:</td>
<td align="left" width="*"><input type="password" name="secretkey" />
<input type="hidden" name="js_autodetect_results" value="0" />
<input type="hidden" name="just_logged_in" value="1" />
</td>
</tr>
</table>
</td>
</tr>
<tr><td align="left"><center><input type="submit" value="ãƒã‚°ã‚¤ãƒ³" />
</center></td>
</tr>
</table>
</center></td>
</tr>
</table>
</form>
</body></html>
What I want to do is to put the username and password in the webpage
and click submit
My code is as follows:
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);
authpost.setRequestBody(new NameValuePair[] {usr, psw,
action});
client.executeMethod(authpost);
System.out.println("Login form post: " +
authpost.getStatusLine().toString());
System.out.println(authpost.getResponseBodyAsString());
authpost.releaseConnection();
}
I know that this doesn't work because of the following question?
1) How to click the button with httpclient API?
2) I feel that the javascript will affect my login?
Can you please help me, I try to find in google for 2 days and try
many example and it doesn't work.
Thank you for reading this post.
best Regards
Ferdinand Ng