On Mon, Jul 06, 2009 at 08:14:48PM +0200, Joan Balaguer? Valls wrote:
> Hello Oleg,
> 
>  
> 
> I?m trying to send cookies to a servlet with a simple app. Following the
> tutorial:
> 
>  
> 
> HttpContext localContext = new BasicHttpContext();
> 
> CookieStore cookieStore  = new BasicCookieStore();
> 
>  
> BasicClientCookie stdCookie = new BasicClientCookie("name", "value");
> stdCookie.setVersion(1);
> stdCookie.setDomain(".mycompany.com");
> stdCookie.setPath("/");
> stdCookie.setSecure(true);
>  
> // Set attributes EXACTLY as sent by the server 
> stdCookie.setAttribute(ClientCookie.VERSION_ATTR, "1");
> stdCookie.setAttribute(ClientCookie.DOMAIN_ATTR, ".mycompany.com");
> 
>  
> 
>  cookieStore.addCookie(stdCookie);
> 
>  localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
> 
>  
> 
>  HttpEntity entity = objHttp.execute(objPost, localContext).getEntity();
> 
>  
> 
>  
> 
> This does not work (at least for me). To work, you need to add:
> 
>  
> 
> stdCookie.setAttribute(ClientCookie.PATH, "/");
>  
> If I forget any of the ?set? statement, or any of the ?setAttribute?
> statement, it does not work.
>  
>  
> The question is: Why have we to set twice the components of the
> ?BasicClientCookie?, the first using ?stdCookie.set? and the second using
> ?stdCookie.setAttribute??
>  
> And should I set ?ClientCookie.SECURE_ATTR? and ?ClientCookie.MAX_AGE_ATTR?
> ?
> 


Joan

This is because some cookies set domain / path / port attributes explicitly,
while some do not, in which case values of those attributes are derived from
the properties of the origin server.

Consider the following example:

Set-Cookie: 
  stuff="very important"; path="/"; domain="myhost.mydomain.com"; version=1
Set-Cookie: 
  stuff="very important"; version=1

These two cookies are obviously different but they essentially represent the
same piece of state information if sent in response to a request for
"http://myhost.mydomain.com/index.html";

 
>  
> And the second part: when the servlet receives this cookie, it is resent to
> another servlet using the same sequence of operations. But debugging, one
> can see that the cookie is not added to the cookieStore (the sentence
> ?cookieStore.addCookie(stdCookie);? does not add anything to ?cookieStore?).
> 

A cookie does not get added to the cookie store only if it has expired.

Hope this helps

Oleg

 
> Can you help me?
>  
>  
> Thanks in advance,
>  
> Joan.
> 
>  
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscr...@hc.apache.org
For additional commands, e-mail: httpclient-users-h...@hc.apache.org

Reply via email to