Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setting Cookie: JSESSIONID on client request manually

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

like image 905
Gazaz Avatar asked Jul 03 '26 04:07

Gazaz


1 Answers

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

like image 127
StanislavL Avatar answered Jul 05 '26 16:07

StanislavL



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!