hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Francois-Xavier Bonnet <francois-xavier.bon...@centraliens.net>
Subject Re: Exception parsing cookies
Date Fri, 15 Mar 2013 09:41:56 GMT
No, you also have to set a CookieStore in the HttpContext. The attributes
in the HttpContext you pass as a parameter take precedence over the default
ones so using an empty HttpContext does not help. Some details here:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html#d5e818

Anyway, in your case the most efficient solution is to tell HttpClient to
ignore cookies instead of creating a HttpContext that will never be reused:
httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
CookiePolicy.IGNORE_COOKIES);


2013/3/15 Albek, Elli (contractor) <ealbek-contractor@shaklee.com>

> Thanks,
>
> To add, the code that use the client (called concurrently by many
> threads):
>
> HttpResponse response = client.execute(call);
>
> HttpEntity entity = response.getEntity();
> if (entity != null) {
>   String body = EntityUtils.toString(entity);
>   String mime = entity.getContentType().getValue();
>   // process response ...
> }
>
> If we use new client.execute(call, new BasicHttpContext()) instead,
>                                    ^^^^^^^^^^^^^^^^^^^^
>
> is that going to create a transient storage for cookies that will not be
> used between calls?
>
> E
>
>
>
> -----Original Message-----
>  Francois-Xavier Bonnet
> Sent: Thursday, March 14, 2013 9:55 PM
> To: HttpComponents Project
> Subject: Re: Exception parsing cookies
>
> I guess the application you are calling is developed with Zend framework
> and the framework is setting automatically this cookie. I don't know if
> there is a way to remove it.
>
> An HttpClient instance has a default CookieStore. If you don't set a
> different HttpContext for each request with a CookieStore in it,
> HttpClient
> will use the same default CookieStore for all users. I think your
> problem
> comes from concurrent accesses to this CookieStore which is not thread
> safe.
>
> If you want to be stateless, I suggest that you set HttpClient to just
> ignore all cookies, this should solve your problem:
> httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,
> CookiePolicy.IGNORE_COOKIES);
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
> For additional commands, e-mail: dev-help@hc.apache.org
>
>

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message