Delphi Web.HTTPApp.TWebRequest RemoteIP VS RemoteAddr

标签 delphi

TWebRequest 有两个方法用于检索客户端 IP 地址:

  1. 远程IP
  2. 远程地址

来自docs of RemoteIP :

Specifies the IP of the remote target machine associated with the HTTP request message. Read the RemoteIP property to obtain the IP address of the remote target machine associated with the HTTP request message.

来自docs of RemoteAddr :

Indicates the remote IP address of the client associated with the HTTP request message. Read RemoteAddr to obtain the IP address of the source of the Web client request.

它们看起来非常接近,但 RemoteIP 返回一个空字符串。 我想检索客户端IP地址,正确的方法是什么?

最佳答案

如果我们查看源代码,我们会在 TWebRequest 的声明中发现以下内容

property RemoteIP: string read GetRemoteIP;
property RemoteAddr: string index 21 read GetStringVariable;

实现:

function TWebRequest.GetRemoteIP: string;
begin
  Result := EmptyStr;
end;

而 GetStringVariable 是一个虚拟方法。

让我们看一下子类之一 - TISAPIRequest,我们会发现以下内容:

LResult := GetFieldByNameA(ServerVariables[Index]);

ServerVariables[21] 是“REMOTE_ADDR” header ,显示客户端或代理服务器的 IP。

但是 GetRemoteIP 没有实现。

请求中似乎没有使用 RemoteIP,因为 TCGIRequest、TApacheRequest 和 TWinCGIRequest 也没有实现 GetRemoteIP。

关于Delphi Web.HTTPApp.TWebRequest RemoteIP VS RemoteAddr,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45920491/

相关文章:

delphi - Delphi 2010 中的 ASyncPro 5.00 - 范围检查错误

delphi - 锁定表 Firebird ,德尔福

delphi - ClientDataset 索引更改时不计算 TAggregateField

delphi - 使用 TForm 作为组件基础时出现资源未找到错误

delphi - FireMonkey Android 与 TIdHTTPServer 的问题

delphi - 如何在XE6上解析 "ITaskbarList3 interface is not supported on this OS version"

delphi - 在 Delphi 或 C++ Builder 中使用 Chromium Edge WebView2

Delphi:无需正则表达式即可验证电子邮件

string - Delphi-如何搜索不完整的字符串匹配项

multithreading - 德尔福 2010 线程