title: Setting and Retrieving Cookies using HttpComponents
body: <p>I am trying to figure out how to set and also retrieve cookies using HttpComponents, but I can't find solid documentation, especially when it comes to setting cookies on the request. What I have seems to work, but at the same time I can't confirm that the cookies I set are being sent correctly.  </p>
  
  <p>I notice that the cookie that I set on the request is also in the CookieStore after calling client.execute(), but I'm not sure if that's just because I add it to the CookieStore before calling client.execute() (maybe it stays in the CookieStore without being actually sent with the request?).  Is there a good way to confirm the cookie is sent?</p>
  
  <pre><code>HttpGet get = new HttpGet("http://example.com/");
  DefaultHttpClient client = new DefaultHttpClient();
  
  // set the cookies
  CookieStore cookieStore = new BasicCookieStore();
  BasicClientCookie cookie = new BasicClientCookie("foo", "bar");
  cookie.setDomain("example.com");
  cookie.setPath("/something/");
  cookieStore.addCookie(cookie);    
  client.setCookieStore(cookieStore);
  
  // get the cookies
  HttpResponse response = client.execute(get);
  List&lt;Cookie&gt; cookies = client.getCookieStore().getCookies();
  </code></pre>