You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Fabien BALAGEAS <fa...@twinsoft.fr> on 2004/08/26 08:46:08 UTC

How to use two distinct HttpClients on the same web site

Hi,
 
I am using HttpClient 2.0.1.
 
I would like to have two HttpClient connections to the same web site in
my application, but from two "distinct" HttpClient (i.e. each connection
should handle its self cookies).
 
How can i realize this task ?
 
Up to now, i only managed to have two connections to the web site, but
with the same cookies sent, so the web site see my two connections as if
they were one.
 
Thanks in advance for your help,
Fabien
 
 
 

Re: How to use two distinct HttpClients on the same web site

Posted by Oleg Kalnichevski <ol...@bearingpoint.com>.
Fabien,

If all you need is to maintain a distinct conversational state per
logical web application hosted on the same physical platform, you should
have just only one HttpClient instance and then keep different HttpState
instances per web application. It does take a bit of HttpState juggling,
but the benefit of such setup will be a better overall performance, as
HttpClient would be able to reuse physical connections to the host.

=================================================================
HttpClient httpclient = new HttpClient();

HttpState httpstate1 = new HttpState();
GetMethod httpget1 = new GetMethod("http://www.whatever.com/app1");
try {
	httpclient.executeMethod(null, httpget1, httpstate1);
	System.out.println(httpget1.getStatusLine()); 
	System.out.println(httpget1.getResponseBodyAsString());
	httpstate1.getCookies();
} finally {
	httpget1.releaseConnection();
}

HttpState httpstate2 = new HttpState();
GetMethod httpget2 = new GetMethod("http://www.whatever.com/app2");
try {
	httpclient.executeMethod(null, httpget2, httpstate2);
	System.out.println(httpget2.getStatusLine()); 
	System.out.println(httpget2.getResponseBodyAsString());
	httpstate2.getCookies();
} finally {
	httpget2.releaseConnection();
}
 
Hope this helps

Oleg

On Thu, 2004-08-26 at 08:46, Fabien BALAGEAS wrote:
> Hi,
>  
> I am using HttpClient 2.0.1.
>  
> I would like to have two HttpClient connections to the same web site in
> my application, but from two "distinct" HttpClient (i.e. each connection
> should handle its self cookies).
>  
> How can i realize this task ?
>  
> Up to now, i only managed to have two connections to the web site, but
> with the same cookies sent, so the web site see my two connections as if
> they were one.
>  
> Thanks in advance for your help,
> Fabien
>  

***************************************************************************************************
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