You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Delphi RAD Server中获取客户端IP地址?

获取RAD Server(Delphi 10.2)中客户端IP地址的方法

在Delphi 10.2的RAD Server中,你可以通过GetItem过程的AContext参数获取客户端IP,具体实现如下:

  • 确保已引用EMS.Services单元
  • 通过AContext.Connection.Channel访问底层通信通道,针对HTTP场景强转为TEMSHTTPChannel后读取RemoteIP属性

示例代码:

uses EMS.Services;

procedure GetItem(const AContext: TEndpointContext; 
  const ARequest: TEndpointRequest; 
  const AResponse: TEndpointResponse);
var
  LClientIP: string;
  LChannel: TEMSChannel;
begin
  LChannel := AContext.Connection.Channel;
  if LChannel is TEMSHTTPChannel then
    LClientIP := TEMSHTTPChannel(LChannel).RemoteIP;
  
  // 示例:将IP返回给客户端
  AResponse.Body.SetValue('客户端IP: ' + LClientIP, True);
end;

说明:

  • TEMSHTTPChannel是RAD Server处理HTTP请求的通道类,RemoteIP属性直接返回发起请求的客户端IP地址
  • 若使用其他通信协议,需对应判断通道类型并读取对应属性,但HTTP场景下上述方法完全适用

内容的提问来源于stack exchange,提问作者Will

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 01:53:10