can you tell me how to store jsessionid in cookie, so it can be passed to the servlet with post request? I\'m using Apache HttpClient version 4.0.3. All the solutions I\'ve
I am so glad to solve this problem:
HttpPost httppost = new HttpPost(postData);
CookieStore cookieStore = new BasicCookieStore();
BasicClientCookie cookie = new BasicClientCookie("JSESSIONID", getSessionId());
//cookie.setDomain("your domain");
cookie.setPath("/");
cookieStore.addCookie(cookie);
client.setCookieStore(cookieStore);
response = client.execute(httppost);
So Easy!
I did it by passing the cookie through the HttpContext:
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
response = client.execute(httppost, localContext);
You should probably set all of the cookie properties not just the value of it. setPath()
, setDomain()
... etc
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
response = client.execute(httppost, localContext);
doesn't work in 4.5 version without
cookie.setDomain(".domain.com");
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");