title: How to add HttpCookies to GET and POST requests in android?
body: <p>I am using HttpCookies to maintain online session on the server. On login, through a POST request, I am getting the cookies using the following code.</p>
  
  <pre><code>HttpPost  httpPost = new HttpPost(url);
  CookieStore store =  ((DefaultHttpClient)client).getCookieStore();
          if(params != null)
              httpPost.setEntity(new UrlEncodedFormEntity(params));
          httpResponse = httpClient.execute(httpPost);
  
          cookies= httpClient.getCookieStore().getCookies();
  
          if(cookies.isEmpty())
          {
              Log.d("Cookies", "None!");
          }
          else
          {
              for (Cookie c : cookies) {
                  Log.d("Cookies","Name ["+c.getName()+"] - Val ["+c.getValue()+"] - Domain ["+c.getDomain()+"] - Path ["+c.getPath()+"]");
                  store.addCookie(c);
              }
          }
  </code></pre>
  
  <p>But the problem is, I am unable to attach the cookies in the next GET request, so as to maintain the session. I have tried the following code, but it's not working.</p>
  
  <pre><code>HttpContext ctx = new BasicHttpContext();
  store.addCookie(singleCookie);
  ctx.setAttribute(ClientContext.COOKIE_STORE, store);
  Log.d("Servicehandler", singleCookie.getValue());
  HttpGet request = new HttpGet();
  request.setURI(new URI(url));
  HttpResponse r_response = client.execute(request, ctx);
  </code></pre>