setting Cookie: JSESSIONID on client request manually

cookies, httprequest, java, swing

Solution

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

Problem

im making a swing application which will sign in to a server; were im using HttpURLConnection to submit my request and get my response. problem is when the httpRequest gets to the server the "Cookie: JSESSIONID" header is there, session id is there; but the request.getSession(false) will always return null. here is the code which i use to set the header on the client: ``` connection.setRequestProperty("Cookie: JSESSIONID", client.getSessionId()); ``` any help would be apprectiated

Original source

Related problems