Web Login

Status
Nicht offen für weitere Antworten.
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:
Code:
http://board.anime-miako.to/login.php
der form login code sieht so aus:
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 :( 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...
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
P Jenkins Login per Java Download Manager Netzwerkprogrammierung 15
T HTTP JSoup Automatic Website Login Netzwerkprogrammierung 1
Q-bert Link zugang ohne login sperren. Netzwerkprogrammierung 1
S Jsoup Login auf Schulserver Netzwerkprogrammierung 3
T Netzwerk Login Felder ansprechen Netzwerkprogrammierung 1
M HTTPS Login & etwas posten Netzwerkprogrammierung 0
M Sicheres Login-System für App implementieren Netzwerkprogrammierung 6
K Login Shibboleth Netzwerkprogrammierung 0
L Mit Java über PHP in MySQL anmelden (Login script) Netzwerkprogrammierung 3
N HTTP Apache 4.2.1 HttpClient 302 nach Login und auf den weiteren Seiten. Netzwerkprogrammierung 5
D HTTP Frage zu Login & Session ID Netzwerkprogrammierung 5
J Login Bereich auf jeder Seite Netzwerkprogrammierung 4
G Cookie Verwaltungs Problem nach Login auf InetSeite (Wo utma-Cookie?) Netzwerkprogrammierung 18
I HTTP S - Zertifikate+Cockies für Form-basierten Login Netzwerkprogrammierung 2
S Automatischer Login auf einer Webseite Netzwerkprogrammierung 12
E Webseite mit Login laden Netzwerkprogrammierung 5
C Login ohne Erfolg Netzwerkprogrammierung 2
xDarkSunx Hilfe Chat Login Netzwerkprogrammierung 7
T Java => Login mit MySQL Netzwerkprogrammierung 10
M Login mit HtmlUnit Netzwerkprogrammierung 6
K Login via apache httpclient Netzwerkprogrammierung 4
N Login mit Roboter Netzwerkprogrammierung 16
S HTTP Login mit CAS Authentisierung über SSL Netzwerkprogrammierung 2
M Servlet als Login Netzwerkprogrammierung 20
J Socket Doppel Login geht nicht Netzwerkprogrammierung 11
N Login auf Website Netzwerkprogrammierung 11
H HTTP Login mit POSTMethod und httpClient Netzwerkprogrammierung 5
K HTTP Login Internetseite Netzwerkprogrammierung 17
lordcarlos HTTP Apache HttpClient, post und login. Netzwerkprogrammierung 2
G ftp login Netzwerkprogrammierung 10
K Bad Request nach Form Login in Jakarta HttpClient Netzwerkprogrammierung 4
H Login Chatsystem Netzwerkprogrammierung 5
2 Redirect, Login und Download bei Rapidshare.com Netzwerkprogrammierung 4
lebenlechzer Login per Telnet auf Router Netzwerkprogrammierung 2
N icq login Netzwerkprogrammierung 16
M Problem: connection abbrechen und login erkennen Netzwerkprogrammierung 2
C Login bei einem php-script Netzwerkprogrammierung 2

Ähnliche Java Themen

Neue Themen


Oben