【问题标题】:Indy http server session doesn't work wellIndy http 服务器会话不能正常工作
【发布时间】:2018-12-07 10:33:23
【问题描述】:

如何在 idhttpserver 中创建会话?

我尝试了很多方法,但我无法在 ARequestInfo.Session 或 AResponseInfo.Session 中访问会话对象,它们都始终为零。请帮忙

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;

【问题讨论】:

  • 在旁注中,您正在泄漏您的 TCommand 对象,因为您在使用完毕后并没有释放它

标签: delphi indy httpserver indy10


【解决方案1】:

确保将TIdHTTPServer.SessionState 设置为True。或者,您也可以将TIdHTTPServer.AutoStartSession 设置为True。默认都是False

如果两者都是True,则无需手动调用CreateSession(),因为它会自动调用每个传入的请求,但不携带现有会话的cookie。

如果SessionState=TrueAutoStartSession=False,您确实需要在需要时手动调用CreateSession()

但是,无论如何,不​​要手动调用SessionList.Add(),因为CreateSession() 在内部会为您调用。您不希望 SessionList 持有对同一个 TIdHTTPSession 对象的多个引用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-04-26
    • 2013-08-10
    • 1970-01-01
    • 2011-11-11
    • 2017-12-28
    • 1970-01-01
    • 2015-01-16
    相关资源
    最近更新 更多