Indy http server session doesn't work well

﹥>﹥吖頭↗ 提交于 2019-12-11 13:29:35

问题


How can create session used with in idhttpserver ?

I tryed alot of ways to do but I can't able to reach session object in ARequestInfo.Session or AResponseInfo.Session these are both of them always nil. please help

procedure TFolsecPermissionManager.IdHTTPServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  Command: TCommand;
  Session: TIdHTTPSession;
begin
  Session := IdHTTPServer.CreateSession(AContext, AResponseInfo, ARequestInfo);
  IdHTTPServer.SessionList.Add(Session);


  Command:= TCommand.Create;
  Command.Start(AContext, ARequestInfo, AResponseInfo);
end;

回答1:


Make sure that TIdHTTPServer.SessionState is set to True. Optionally, you can also set TIdHTTPServer.AutoStartSession to True as well. They are both False by default.

If both are True, you do not need to call CreateSession() manually, as it called automatically for every incoming request that does not carry a cookie for an existing session.

If SessionState=True and AutoStartSession=False, you do need to call CreateSession() manually when desired.

However, no matter what, do not call SessionList.Add() manually, as CreateSession() calls that internally for you. You don't want the SessionList holding multiple references to the same TIdHTTPSession object.



来源:https://stackoverflow.com/questions/53667736/indy-http-server-session-doesnt-work-well

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!