You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Andrea Sodomaco <an...@sodomaco.it> on 2005/05/25 17:15:27 UTC

[HttpClient] R: R: session maintenance with two different HttpClient objects

Hi Naresh,
More than 1 cookie may be involved (as Oleg Kalnichevski said).
You can extract all with

Cookie[] allCookies= obj1.getState().getCookies();

Store all of them in a file and then use them when you call getDetails()
using something like

HttpState hs=new HttpState();

	hs.addCookie(...);
	hs.addCookie(...);	
	hs.addCookie(...);

	obj2.setState(hs);

If it doesn't work you can check if this is any difference in the header
of the request between obj2.setState(obj1.getState()); and your method.

The 2 request are done from the same IP? Some systems may check if the
information stored in the cookie match the IP.

Andrea Sodomaco



-----Messaggio originale-----
Da: Naresh Agarwal [mailto:naresh_iitd@yahoo.com] 
Inviato: mercoledì 25 maggio 2005 14.07
A: HttpClient User Discussion
Oggetto: Re: R: session maintenance with two different HttpClient
objects

Hi
 
This works. But I don't have access to obj1 when I'm calling
"getDetails" using obj2.
 
I'm calling "login" and "getDetails" in two different entities using
obj1 and obj2 respectively, which *cannot* share anything in memory.
However I can extract cookie from response of "login", store the cookie
in some file and read this cookie from the file to set it in obj2 before
calling "getDetails. 
 
But this is not working from me.
 
thanks,
Naresh 

Andrea Sodomaco <an...@sodomaco.it> wrote:
Hi, 
Try 
obj2.setState(obj1.getState());

can it help you?

Andrea Sodomaco


-----Messaggio originale-----
Da: Naresh Agarwal [mailto:naresh_iitd@yahoo.com] 
Inviato: lunedì 23 maggio 2005 15.32
A: httpclient-user@jakarta.apache.org
Oggetto: session maintenance with two different HttpClient objects

Hi 

I'm using HttpClient library for writing a specialized http client.

Let's say I have two instances of HttpClient object obj1 and obj2, which
communicate with same application running in web server. This
application provide two operations - "login" and "getDetails", which
need session maintenance using cookies. 

I am using obj1 and obj2 as follows - 

1. Call "login" operation using obj1 and extract the cookie from the
response.
2. Call "getDetails" operation using obj2 after setting cookie
extracted in step 1.

But my "getDetails" fails saying that login is required. However, if I
use obj1 in step 2, it works fine.

Basically, I've a special requirement to use *two different* instances
of HttpClient to communicate with same web service (which needs session
maintenance).

Am I missing something? Does session maintenace works only if all the
operations are called using same HttpClient object?

Any help will be greatly appreciated.

thanks & regards,
Naresh Agarwal

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 


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


		
---------------------------------
Do You Yahoo!?
 Yahoo! Small Business - Try our new Resources site!


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