L
Lift
Gast
Hallo,
hab ein großes porblem undzwar will ich mit meinem code mich in eine seite einlogen aber das will nicht richtig klappen
die seite benutzt form login, ich bekomme schon die passenden cookies aber keine redirect -.-
die seite in der ich mich zu test zwecken einloggen will heisst: http://board.anime-miako.to/login.php
der form login code sieht so aus:
der form login code sieht so aus:
und mein code dazu so:
ich habe schon alles möglich und mir bekannte gemacht damit das irgendwie klappt -.- ich habe dieses board durchgesucht sowie google aber leider ohne erfolg
es wäre wirklich eine goße hilfe wenn ihr mir irgendetwas geben könntet das mich auf den weg zur lösung führt...
hab ein großes porblem undzwar will ich mit meinem code mich in eine seite einlogen aber das will nicht richtig klappen
die seite benutzt form login, ich bekomme schon die passenden cookies aber keine redirect -.-
die seite in der ich mich zu test zwecken einloggen will heisst: http://board.anime-miako.to/login.php
der form login code sieht so aus:
Code:
http://board.anime-miako.to/login.php
Code:
<form action="login.php" method="post" name="loginform">
<input type="hidden" name="send" value="send" />
<input type="hidden" name="sid" value="" />
<table cellpadding="4" cellspacing="1" border="0" class="tableinborder">
<tr>
<td class="tabletitle" align="left" colspan="2"><span class="normalfont">[b]Anmeldung[/b]</span></td>
</tr>
<tr align="left">
<td class="tableb"><span class="normalfont">Benutzername:</span></td>
<td class="tableb"><input type="text" class="input" name="l_username" size="20" maxlength="50" tabindex="1" /><span class="smallfont"> [url="register.php"]Registrierung[/url]</span></td>
</tr>
<tr align="left">
<td class="tablea"><span class="normalfont">Passwort:</span></td>
<td class="tablea"><input type="password" class="input" name="l_password" size="20" maxlength="30" tabindex="2" /><span class="smallfont"> [url="forgotpw.php"]Passwort vergessen[/url]</span></td>
</tr>
</table>
<p align="center"><input class="input" type="submit" name="submit" accesskey="S" value="Anmelden" tabindex="3" /> <input class="input" type="reset" accesskey="R" value="L&schen" /></p>
</form>
und mein code dazu so:
Code:
import java.util.Scanner;
import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.cookie.CookiePolicy;
import org.apache.commons.httpclient.cookie.CookieSpec;
import org.apache.commons.httpclient.methods.*;
public class FormLoginDemo
{
static final String LOGON_SITE = "board.anime-miako.to";
static final int LOGON_PORT = 80;
public FormLoginDemo() {
super();
}
public static void main(String[] args) throws Exception {
HttpClient client = new HttpClient();
client.getHostConfiguration().setHost(LOGON_SITE, LOGON_PORT, "http");
client.getParams().setCookiePolicy(CookiePolicy.DEFAULT);
GetMethod authget = new GetMethod("/login.php");
client.executeMethod(authget);
System.out.println("Login form get: " + authget.getStatusLine().toString());
authget.releaseConnection();
CookieSpec cookiespec = CookiePolicy.getDefaultSpec();
Cookie[] initcookies = cookiespec.match(
LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies());
System.out.println("Initial set of cookies:");
if (initcookies.length == 0) {
System.out.println("None");
} else {
for (int i = 0; i < initcookies.length; i++) {
System.out.println("- " + initcookies[i].toExternalForm());
}
}
PostMethod authpost = new PostMethod("/login.php");
NameValuePair action = new NameValuePair("action", "/login.php");
NameValuePair userid = new NameValuePair("l_username", "asd");
NameValuePair password = new NameValuePair("l_password", "asd");
NameValuePair send = new NameValuePair("send","send");
NameValuePair sid = new NameValuePair("sid", "");
authpost.setRequestBody(
new NameValuePair[] {action, userid, password, send, sid});
client.executeMethod(authpost);
System.out.println("Login form post: " + authpost.getStatusLine().toString());
authpost.releaseConnection();
Cookie[] logoncookies = cookiespec.match(
LOGON_SITE, LOGON_PORT, "/", false, client.getState().getCookies());
System.out.println("Logon cookies:");
if (logoncookies.length == 0) {
System.out.println("None");
} else {
for (int i = 0; i < logoncookies.length; i++) {
System.out.println("- " + logoncookies[i].toString());
}
}
int statuscode = authpost.getStatusCode();
System.out.println(statuscode);
try{
Scanner scanner = new Scanner(authpost.getResponseBodyAsStream());
String text;
while((scanner.hasNext())== true){
text = scanner.nextLine();
System.out.println(text);
}
scanner.close();
}catch(NullPointerException e){
System.out.println(e);
System.exit(1);
}
/*
if ((statuscode == HttpStatus.SC_MOVED_TEMPORARILY) ||
(statuscode == HttpStatus.SC_MOVED_PERMANENTLY) ||
(statuscode == HttpStatus.SC_SEE_OTHER) ||
(statuscode == HttpStatus.SC_TEMPORARY_REDIRECT)) {
Header header = authpost.getResponseHeader("location");
if (header != null) {
String newuri = header.getValue();
if ((newuri == null) || (newuri.equals(""))) {
newuri = "/";
}
System.out.println("Redirect target: " + newuri);
GetMethod redirect = new GetMethod(newuri);
client.executeMethod(redirect);
System.out.println("Redirect: " + redirect.getStatusLine().toString());
// release any connection resources used by the method
redirect.releaseConnection();
} else {
System.out.println("Invalid redirect");
System.exit(1);
}
}*/
}
}
ich habe schon alles möglich und mir bekannte gemacht damit das irgendwie klappt -.- ich habe dieses board durchgesucht sowie google aber leider ohne erfolg