Apache Httpclient 4.0.3 - How to Set Cookie with Sessionid for Post Request

setting Cookie: JSESSIONID on client request manually

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);

See also this Java: How to make a HTTP browsing session and this Apache HttpClient 4.0.3 - how do I set cookie with sessionID for POST request

Why is httpclient is refreshing the jsession id for every request?

Found the answer on the same day I posted this question.. thought of sharing..
The answer is very simple.. For some reasons the authentication wasn't successful, hence the new jsessionId was created. Replaced "httpClient.getCredentialsProvider().setCredentials()" with "BasicNameValuePair" and it worked :)



Related Topics



Leave a reply



Submit