Hi,
I'm trying to login on an internet Page. I've been googeling and trying to find the right way to achieve this. What i got this far is:
I'm using the Apache package (HttpClient, Code, Logging).
import java.io.*;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.Header;
public class TestCode {
static final String loginSite = "****";
static final String checkSite = "****";
public static void main(String[] args) throws Exception{
HttpClient client = new HttpClient();
cient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
PostMethod post = new PostMethod(loginSite);
post.setRequestHeader(new Header("User-Agent", "****"));
post.addParameter("name","****");
post.addParameter("password","****");
post.addParameter("button_name","****");
client.executeMethod(post);
BufferedReader in = new BufferedReader(
new InputStreamReader(
post.getResponseBodyAsStream()));
String decodedString;
while ((decodedString = in.readLine()) != null) {
System.out.println(decodedString);
}
in.close();
post.releaseConnection();
}
}
This is the Internet Packe i'm trying to log in:
<<pre lang="xml">form method="post" name="post_name" action="TMP.php">
<table cellpadding="1" cellspacing="1" id="login_form">
<tbody>
<tr class="top">
<th>Enter Name:</th>
<td>
<input class="text" type="text" name="name" value="Login_Name_Here" /> <span class="error"> </span>
</td>
</tr>
<tr class="btm">
<th>Enter Password:</th>
<td>
<input class="text" type="password" name="password" value=""
maxlength="20" /> <span class="error"> </span>
</td>
</tr>
</tbody>
</table>
<p class="btn">
<input type="image" value="login" name="button_name" onclick="xy();" id="btn_login" class="dynamic_img" src="img/x.gif" alt="Login-Button" />
<input type="hidden" name="w" value="" />
<input type="hidden" name="login" value="99999999" />
</p>
</form>
In the response i get, the password & name is fild in.
I'm not sure if i have to "press" the Button or not.
Also wenn i get the response i'm still on the login page (name & password ist fild in the under "value").
Usually when i login on my browser the i-net page sends me to an other page
(Just changed the page: TMP.php).
Anyone has a clue?
Thanks in advance.
----------------------------------------------------------------
Ok, it's me again,
right now i'm trying on an easier example. No login!
But still i don't get the PostMethod...
What works & and what i understand is the GetMethod:
http://hc.apache.org/httpclient-3.x/tutorial.html
-> I get the information of the internet page.
But what doesn't work still is the PostMethod:
http://hc.apache.org/httpclient-3.x/methods/post.html
-> Here I get the same information (like with GetMethod)
Has anybody a working PostMethod example on an excisting internet page??
Any help is appreciated