Post-Methode und HTTPClient ?

Status
Nicht offen für weitere Antworten.

Verjigorm

Top Contributor
Hallo,
ich versuche seit Wochen nen Login mit HTTPClient von jakarta hinzubekommen und ich bin echt fast am verzweifeln
Ich finde dazu irgendwie nur schrottige Beispiele und kriege bald die Krise 🙂

der Form-tag sieht so aus:

Code:
...
<form name="form_login" method="post" action="index.php?L=1">
        <input type="hidden" name="formsend" id="formsend" value="1">
        <input type="hidden" name="aktion" id="aktion" value="">
 
                                         User: <input onFocus="javascript:this.select();" class="main" type="text" name="user" id="user" value="" 
                                         Password: <input onFocus="javascript:this.select();" class="main" type="password" name="password" id="password" value="" 
                                         <input class="main" type="submit" name="login" id="login" value="Login" />
  
</form>
...

kann mir wer verraten, wie das funktionieren soll?

ich könnte nun anfangen 27 einzelne angefange Codes zu posten mit denen ich das alles schon versucht habe, aber ich glaube dass hilft euch nicht weiter

würde mich über einige Tipps oder sonstiges freuen
 
also mal ein Beispiel, was ich versucht habe :
(hier weiss ich nichtmal ob das überhaupt stimmt)

Code:
package test;

import org.apache.commons.httpclient.*;
import org.apache.commons.httpclient.methods.*;

public class HttpClientTest {
 public static void main( String[] args ) {
   String url = "http://localhost/blablubburl";
   try {
    HttpClient client = new HttpClient();
    PostMethod method = new PostMethod( url );

	 // Configure the form parameters
	 method.addParameter( "formsend", "1" );
	 method.addParameter( "aktion", "" );
	 method.addParameter( "user", "root" );
	 method.addParameter( "password", "root" );
	 method.addParameter( "login", "Login" );

	 // Execute the POST method
    int statusCode = client.executeMethod( method );
    if( statusCode != -1 ) {
      String contents = method.getResponseBodyAsString();
      method.releaseConnection();
      System.out.println( contents );
    }
   }
   catch( Exception e ) {
    e.printStackTrace();
   }
 }
}

dann kriege ich als Fehler:

28.12.2006 21:21:11 org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded
INFO: Redirect requested but followRedirects is disabled

wenn ich dann method.setFollowRedirects(true); einfüge kommt folgendes:

java.lang.IllegalArgumentException: Entity enclosing requests cannot be redirected without user intervention
at org.apache.commons.httpclient.methods.EntityEnclosingMethod.setFollowRedirects(EntityEnclosingMethod.java:221)
at test.HttpClientTest.main(HttpClientTest.java:20)

ich hab keinen Plan wie ich was noch weiter oder anders machen muss/kann
wo mein fehler liegt (bzw mehrere Fehler 😀 )
ich hab mich dann durch massig mailing-archive etc gegooglt aber bin der lösung des problems seit wochen nicht näher gekommen
ich werd noch bescheuert :\
 
Status
Nicht offen für weitere Antworten.

Zurück
Oben