在 Rails 应用程序上使用 HTTPClient 维护会话
我有一个与 Rails 应用程序对话的小程序。我希望维护用户的会话,以便小程序的通信被识别为用户浏览会话的一部分。我使用 apache 的 HTTPClient 发送请求,但 Rails 应用程序无法将该请求识别为用户会话的一部分。
这是我用来构建请求的代码,我传入 session_id 变量和 HTTP_COOKIE 变量作为小程序参数:
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");
任何建议都会很棒!
懒惰型
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我用以下代码解决了这个问题:
这两个问题是:
1)没有将端口号放入 url 中。
2) 指定了错误的会话 ID。在此示例中,应用程序称为chatter,因此session_id 为_chatter_session。我将会话 ID 作为参数添加到小程序中。
I solved this with the following code:
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.