I have an applet that talks with a Rails Application. I wish to maintain a user's session so that the applet's communication is recognized as part of a user's browsing session. I use apache's HTTPClient to send the request but the rails application does not recognize the request as part of the users session.
This is the code that I use to build the request, I pass in session_id variable and the HTTP_COOKIE variable as applet parameters:
HttpClient client = new HttpClient();
Cookie httpCookie = new Cookie("localhost", "HTTP_COOKIE", http_cookie, "/", null, false);
Cookie sessionID = new Cookie("localhost", "session_id", session_id, "/", null, false);
HttpState initialState = new HttpState();
initialState.addCookie(httpCookie);
initialState.addCookie(sessionID);
client.setState(initialState);
PostMethod post = new PostMethod("http://localhost:3001/vizs/add");
Any suggestions would be great!
slothishtype
I solved this with the following code:
String session_id_str = "6a7eec105k231g51bjd0655e638034f3";
Cookie sessionID = new Cookie("127.0.0.1:3001", "_chatter_session", session_id_str, "/", null, false);
HttpState initialState = new HttpState();
initialState.addCookie(sessionID);
client.setState(initialState);
The two problems were:
1) Not putting the port number in the url.
2) Specifying the wrong session id. In this example the application is called chatter so the session_id is _chatter_session. I add the session id to the applet as a parameter.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.