如何在资源控制器中获取客户端远程IP地址

How to get client remote ip address in resource controller

如何在资源控制器的函数中访问 request.connectioninfo.remoteaddress?我需要存储和记录客户端远程 IP。

使用请求的原始 属性 https://pub.dartlang.org/documentation/aqueduct/latest/aqueduct/Request/raw.html

CA 编辑: 请求对象已经存在于从 ResourceController 或 Controller 扩展的控制器中,可以简单地这样使用:

final remote_address = request.raw.connectionInfo.remoteAddress.address;

你不能绑定它,但你可以用同样的方式访问它。该请求可用作资源控制器的 属性,因此它在每个方法中都可用。