虽然以前有一些获取客户端IP地址(例如req.peerHostname )的方法,但我无法在Vapor3.0中找到它。
有谁能告诉我如何在Vapor 3.0中获取客户IP地址吗?
发布于 2018-05-25 04:11:39
多亏了Vapor社区,我得到了答案。
您可以在Vapor3.0项目中使用req.http.remotePeer.hostname。
发布于 2021-01-28 20:41:04
希望这对Vapor 4的使用有所帮助
func getIp(req: Request) throws -> EventLoopFuture<String> {
print(req.headers.forwarded.first!.for)
return req.eventLoop.makeSucceededFuture("\(req.headers.forwarded.first!.for ?? "Not found")")
}对我来说很好,不是我想的最好的解决方案,但它有效:)
发布于 2022-04-15 19:29:37
对于Vapor 4,使用以下内容
req.remoteAddress?.ipAddresshttps://stackoverflow.com/questions/50502003
复制相似问题