Delphi XE3 DataSnap Server中的访问请求标头 [英] Access Request Header in Delphi XE3 DataSnap Server
问题描述
我正在Delphi XE3中实现REST服务器API(大约十年来第一次使用Delphi,所以有点生锈)。当前,它使用Indy服务器进行调试,但最终它将是ISAPI dll。
I am implementing a REST server API in Delphi XE3 (first time using Delphi in about a decade so am a bit rusty). Currently it is using Indy server for debug purposes, but eventually it will be an ISAPI dll.
现在,我已经实现了许多TDSServerClass类,并且想要访问请求标头类方法中。因此,例如,当用户请求mysite.com/datasnap/rest/foo/bar时,我希望能够读取名为bar的foo类方法中的标头。这可能吗?
Now I have implemented a number of TDSServerClass classes and want to access the request header within the class methods. So for example when the user requests mysite.com/datasnap/rest/foo/bar I want to be able to read the header within the foo class method called bar. Is this possible?
如果没有,是否可以在传入请求到达REST类方法之前创建全局过滤器?我需要检查传入请求的API密钥和用户身份验证,并且不确定实现的最佳方法。谢谢。
If not, is it possible to create a global filter of incoming requests before they get to the REST class method? I need to check the API key and user authentication on incoming requests and not sure the best way to implement. Thanks.
推荐答案
我不知道XE3中是否有任何更改,但是在XE2中,您可以执行以下操作:
I don't know if anything changed in XE3, but in XE2 you can do the following:
uses
Web.HTTPApp,
Datasnap.DSHTTPWebBroker;
function TServerMethods1.EchoString(Value: string): string;
var
Module: TWebModule;
begin
Module := GetDataSnapWebModule;
Result := Module.Request.RemoteIP + ': ' + Value;
end;
这篇关于Delphi XE3 DataSnap Server中的访问请求标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!