hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Marcelo Chryssovergis" <marcel...@iea.org.br>
Subject RES: RES: Problem with login!! (cookies)
Date Tue, 19 Jul 2005 13:22:11 GMT

Hi Roland,
Thanks for your reply

The random value I mentioned is a alfanumeric sequence in a hidden field,
that needs to be resent to the server to verify the validity of the session
during the login process.

The problem is that this sequence comes when I load the login page, and the
same sequence has to be sent when I submit the form. This is the browser
procedure.

In my java application I just send my login data with a PostMethod, meaning
I don’t have the original random sequence of characters that would be sent
to me when I "open the website". What I am doing is use a GetMethod to fetch
the source code once, get the random key, and do the PostMethod then, but I
don´t know if the key is the expected one...

Actually I don’t know if THIS is my problem. But, this is my guess, as long
I´m getting error while trying to login.


Any sugestions?
Thanks!
Marcelo




-----Mensagem original-----
De: Roland Weber [mailto:ROLWEBER@de.ibm.com] 
Enviada em: segunda-feira, 18 de julho de 2005 11:58
Para: HttpClient User Discussion
Assunto: Re: RES: Problem with login!! (cookies)

Hello Marcelo,

why do you process the cookies from httpClient.getState() if
you're only putting them back into httpClient.getState()?
Just do nothing and they'll stay where they are.

> Another site I have to login, generates a random
> key each time we access.

What kind of random key? A random value for a cookie, or a
cookie with a random name, or a POST parameter with a random
value (or name) or a random segment in the URL path or a random
key as a URL parameter?

If it's a cookie, just do nothing. Use the same HttpState for all
requests to the server and HttpClient will automatically update
the cookies in the state with each request. You may have to set
the appropriate cookie policy for the server.

If it's a POST or URL parameter, add the parameter to the
body or URL for the next request. If it's part of the URL path,
then compute the next URL dynamically with the appropriate key.

hope that helps,
  Roland





"Marcelo Chryssovergis" <marcelodc@iea.org.br> 
18.07.2005 11:29
Please respond to
"HttpClient User Discussion"


To
"'HttpClient User Discussion'" <httpclient-user@jakarta.apache.org>
cc

Subject
RES: Problem with login!! (cookies)






Okay, problem solved. I realized that it was necessary to edit the cookie 
to
change the expiration date (originally it was null, meaning it would exist
until the end of the session, but.. aparently it does not works in the 
same
way in java applications)

Now I have another issue: Another site I have to login, generates a random
key each time we access. I can find dinamically the key without problem, 
but
I use the PostMethod to send the login information, and when I execute 
this
method, I believe a random key is generated again!

What can I do?

Thanks,

Marcelo







-----Mensagem original-----
De: Marcelo Chryssovergis [mailto:marcelodc@iea.org.br] 
Enviada em: sexta-feira, 15 de julho de 2005 11:41
Para: httpclient-user@jakarta.apache.org
Assunto: Problem with login!! (cookies)

Hello all!!

 

I´m having a little big problem here with cookies. 

The situation is: I have to login to a site who manages cookies during 
login
process. That´s ok, that´s normal. What is my problem then? Well, 
SOMETIMES
it works, ALMOST EVERY TIME it does not work.

WHEN it works once, it works all the retrys I do after, until I restart 
the
computer. After restarting the computer, I cannot login into the site 
again.
I don’t understand why.

 

Please, any sugestion is welcome. 

 

Here is the code:

 

 

Enter the site:

 

 httpClient.getState().setCookiePolicy(CookiePolicy.COMPATIBILITY);


          method = new GetMethod(url); 

          statusCode = httpClient.executeMethod(method);  

          InputStream inp = method.getResponseBodyAsStream();

          BufferedReader br = new BufferedReader(new
InputStreamReader(inp));

          String string = "";

          x = null; x = new StringBuffer();

          while ((string = br.readLine()) != null) 

               x.append(string);

          method.releaseConnection();

 

Submit the login informations:

 

          for (int i = 0; i < tuplasLogin.size(); i++) {

               String campo =
((Vector)tuplasLogin.elementAt(i)).elementAt(1).toString();

               String valor =
((Vector)tuplasLogin.elementAt(i)).elementAt(2).toString();

               String url =
((Vector)tuplasLogin.elementAt(i)).elementAt(3).toString();

 

               if (new String(valor).equals(new String("buscaNoSite"))){

                  valor = buscaValorInput(campo);

               }

 

               method2.addParameter(campo, valor);

 

              if (!new String(url).equals(urlLogin)) {

                   int stat = httpClient.executeMethod(method2);

                   method2.releaseConnection();

                   method2 = new PostMethod(url);

               } 

          }

 

           statusCode = httpClient.executeMethod(method2);

           method2.releaseConnection();

 

Get the cookies:

 

           Cookie[] cookies = httpClient.getState().getCookies();

 

Fetch a login-protected url:

 

          httpClient.getState().addCookies(cookies);

          for (int k = 0; k < cookies.length; k++) {

              Cookie[] arrCookie=
spec.parse(cookies[k].getDomain(),80,cookies[k].getPath(),cookies[k].getSecu
re(),cookies[k].getValue());

              httpClient.getState().addCookies(arrCookie); 

          }

          method = new GetMethod(urlAfterLogin); 

          statusCode = httpClient.executeMethod(method); 

          inp = method.getResponseBodyAsStream();

          br = new BufferedReader(new InputStreamReader(inp));

          string = "";

          x = null; x = new StringBuffer();

          while ((string = br.readLine()) != null) {

             x.append(string);

          }

          method.releaseConnection(); 

 

 

 

Thanks in advance!

 

 

Marcelo Chryssovergis
Analista de Sistemas - Instituto de Estudos Avançados - IEA
+55 (48) 3025.8124
www.iea.org.br 

 





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







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


Mime
View raw message