Hi Roland,

Thank you for your answer.
Yes, I use the same object. In fact, I've implemented the singleton
pattern:

public class CookieDemoApp {
        
        private static CookieDemoApp _instance;
    
        private HttpClient httpclient;
...
...
public static CookieDemoApp getInstance(){
        if (_instance == null){
                _instance = new CookieDemoApp();
        }
        return _instance;
    }
    
    private CookieDemoApp(){
        HttpState initialState = new HttpState();       
        httpclient = new HttpClient();
 
httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(3
0000);
        httpclient.setState(initialState);
 
httpclient.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILIT
Y);
    }

public void connect(String strURL) throws Exception {
        System.out.println("Target URL: " + strURL);
        
        // Get HTTP GET method
        GetMethod httpget = new GetMethod(strURL);
        ...
        ...


And the caller is:

CookieDemoApp demo = CookieDemoApp.getInstance();
        
demo.connect("http://www-dev.fundacionolgatorres.org/estructura/idioma/c
ambiar_idioma.php?Mg%3D%3D");
        
demo.connect("http://www-dev.fundacionolgatorres.org/index.php";);


Prints to console, (sorry, the urls are not public):

Target URL:
http://www-dev.fundacionolgatorres.org/estructura/idioma/cambiar_idioma.
php?Mg%3D%3D
Response status code: 200
Present cookies: 
 - PHPSESSID=47b53d8001c9de9c25f6c877151a0566
 - cookIdioma=2    <---- it means english language, so the cookie
information is ok.

Target URL: http://www-dev.fundacionolgatorres.org/index.php
Response status code: 200
Present cookies: 
 - PHPSESSID=47b53d8001c9de9c25f6c877151a0566
 - cookIdioma=2 <--- ok
Not found!    <--- it means the resulted page is incorrect. Returns page
in default language (spanish)

Any suggestions?
Thanks again!


-----Mensaje original-----
De: Roland Weber [mailto:[EMAIL PROTECTED] 
Enviado el: viernes, 03 de febrero de 2006 7:22
Para: HttpClient User Discussion
Asunto: Re: Persistent connections

Hi Juan,

"Juan Luis de Amaya Robles" <[EMAIL PROTECTED]> wrote on
02.02.2006 19:48:50:

> I have two urls to call (PHP pages). One sets a language variable in 
> session. Another returns data depending on the session var.
> 
> i think, i need stablish persistent connection to connect web pages 
> with session data.

No. If connections were persistent, you wouldn't need a session.

> When i call the first one url, it returns a cookie with a PHPSESSID 
> (it's a php). ok.
> I understand that cookie is sended when I call the second one url, but

> i get a incorrect second page, well, the language is not correct.
> This is because the session is incorrect. I think.

Quite possible. Make sure you use the same HttpClient object for both
requests.
Check out our cookie guide to see whether your problem is addressed
there:

http://jakarta.apache.org/commons/httpclient/cookies.html

> When i print the "isPersistent()" method is returned false. I must 
> configure anything else?
> where the cookie is stored?

HttpClient never stores persistent cookies anywhere but in memory.
By default, they are put into the state of the HttpClient object.
Make sure you use the same HttpClient object for both request. Don't
pass an explicit state to the second request. Try the "browser
compatibility" cookie spec, since some servers send domain names without
a leading dot.

hope that helps,
  Roland


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


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

Reply via email to