delphi - Indy http 服务器会话不能正常工作
问题描述
如何创建与 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;
解决方案
确保TIdHTTPServer.SessionState
设置为True
. 或者,您也可以设置TIdHTTPServer.AutoStartSession
为True
。默认情况下,它们都是False
。
如果两者都是True
,则不需要CreateSession()
手动调用,因为它会自动调用每个不携带现有会话 cookie 的传入请求。
如果SessionState=True
和AutoStartSession=False
,您确实需要在需要CreateSession()
时手动调用。
但是,无论如何,不要SessionList.Add()
手动CreateSession()
调用,因为在内部为您调用。您不希望SessionList
持有对同一TIdHTTPSession
对象的多个引用。
推荐阅读
- python - 将 Django 迁移合并到一个包中
- c++ - 我正在尝试在 Embarcadero Dev-C++ 上打印国际字符,但它们总是出错
- wordpress - 为什么我在 Timber/Twig 中的操作符不适用于我的条件语句?
- google-apps-script - 如何检查列中的值
- javascript - 如何将事件侦听器添加到添加到 UI5 中的 XML 视图的 HTML 画布元素?
- c++ - C++:继承的类具有同名的纯虚函数。如何在我的基类中单独覆盖它们?
- python - 如何使用python将列表值打印为csv中的每一行?
- php - 警告:require_once(/HTML/Template/ITX.php):无法打开流:第 13 行的 C:\wamp64\www\mysite\main\login.php 中没有这样的文件或目录
- vsto - Outlook 弹出框以更正用户
- python-3.x - 我需要帮助来更改数据框列和索引以将其设置为值