hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Kalnichevski, Oleg" <oleg.kalnichev...@bearingpoint.com>
Subject RE: HttpClient login error
Date Wed, 07 Apr 2004 16:36:29 GMT

Gregory,
Does the site in question require authentication? If yes, it is quite likely you have hit
one of the known limitations of the HttpClient 2.0 branch. See HttpClient SSL guide for details
<http://jakarta.apache.org/commons/httpclient/sslguide.html>. This problem has already
been fixed in the development (pre 3.0-alpha1) version.

However, to be really sure you may want to examine the wire log of the HTTP session and see
what exactly goes wrong <http://jakarta.apache.org/commons/httpclient/logging.html>.
Feel free to post the wire log to this mailing list if you think we may be of help. You should
obfuscate sensitive data (such as user credentials and host names) before posting the log,
though.

Oleg





-----Original Message-----
From: Grigorios Merenidis [mailto:grego501@gmx.net]
Sent: Wednesday, April 07, 2004 18:20
To: commons-httpclient-dev@jakarta.apache.org
Subject: HttpClient login error


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: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


***************************************************************************************************
The information in this email is confidential and may be legally privileged.  Access to this
email by anyone other than the intended addressee is unauthorized.  If you are not the intended
recipient of this message, any review, disclosure, copying, distribution, retention, or any
action taken or omitted to be taken in reliance on it is prohibited and may be unlawful. 
If you are not the intended recipient, please reply to or forward a copy of this message to
the sender and delete the message, any attachments, and any copies thereof from your system.
***************************************************************************************************

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-httpclient-dev-help@jakarta.apache.org


Mime
View raw message