setting Cookie: JSESSIONID on client request manually

34,678
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

Share:
34,678
Gazaz
Author by

Gazaz

Updated on November 19, 2020

Comments

  • Gazaz
    Gazaz over 3 years

    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