Hi all!

I try to login on the site

http://www.mercedes-benz.t-online.de

but it is never successful.
I try to connect from my java application over a proxy to the destinated
server.
The connection over the proxy works fine.

My java code looks like this:

static final String LOGON_SITE = "https://www.mercedes-benz.t-online.de";;
static final int LOGON_PORT = 443;
static final String authURL = "/mb-portal/www/Forward";

HttpClient client = new HttpClient();
HostConfiguration hostConfiguration = new HostConfiguration();
try{
     client.setConnectionTimeout(60000);
     client.setTimeout(30000);
     hostConfiguration.setProxy("xx.yyy.zz.xxx", 80);
     client.setHostConfiguration(hostConfiguration);
     client.getHostConfiguration().setHost(LOGON_SITE,
     LOGON_PORT, "https");
     client.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);
     GetMethod authget = new GetMethod();
     authget.setRequestHeader(userAgentHeader);
     authget.setFollowRedirects(true);
     client.executeMethod(authget);
     String responseBody = authget.getResponseBodyAsString();
     authget.releaseConnection();
     Cookie[] initCookies = client.getState().getCookies(LOGON_SITE,
LOGON_PORT, "/", false); 
     System.out.println(responseBody);
     if(initCookies.length==0){
          System.out.println("NONE in GET-Method: " + authget.getPath());
     }else{
         for (int z=0;z<initCookies.length;z++){
               System.out.println("- " + initCookies[z].toString());
          }
     }
     }catch(Exception ex){
        System.out.println(ex.getMessage());
     }

        
     PostMethod authpost = new PostMethod("/mb-portal/www/Forward");
     NameValuePair userid = new NameValuePair("userName", "myUserName");
     NameValuePair password = new NameValuePair("passwd", "myPassword");
     authpost.setRequestBody(new NameValuePair[]{userid, password});
     authpost.setHostConfiguration(hostConfiguration);
     client.executeMethod(authpost);
     System.out.println("Login form post: " +
authpost.getStatusLine().toString());
     authpost.releaseConnection();
     Cookie[] logonCookies = client.getState().getCookies(LOGON_SITE,
LOGON_PORT, "/", false);
     if(logonCookies.length==0){ 
          System.out.println("NONE IN POST-Method");
     }else{
          for (int z=0;z<logonCookies.length;z++){
                System.out.println("- " + logonCookies[z].toString());
          }
     }
     int statuscode = authpost.getStatusCode();
     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);
                }
        redirect.releaseConnection();
          }else{
        System.out.println("invalid redirect");
        System.exit(1);
          }
      }
}

What I am doing wrong?
I would appreciate every help!!!

Thanks,

Gregory

-- 
NEU : GMX Internet.FreeDSL
Ab sofort DSL-Tarif ohne Grundgebühr: http://www.gmx.net/info


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to