我的应用程序中有以下框架
Ninja, Akka, Spray
如何获取客户端请求的 ip 地址?
我的路由定义如下:
router.GET.route(urlPrefix + "/method").`with`(classOf[Controller],"method")
我的应用程序中有以下框架
Ninja, Akka, Spray
如何获取客户端请求的 ip 地址?
我的路由定义如下:
router.GET.route(urlPrefix + "/method").`with`(classOf[Controller],"method")
我不确定您的问题是指www.ninjaframework.org还是spray.io,但如果您使用的是前者,您可以在控制器方法中获取远程 IP 地址:
public Result method(Context context) {
String ip = context.getRemoteAddr();
// ...
}
如文档所述(http://www.ninjaframework.org/apidocs/ninja/Context.html#getRemoteAddr--),如果您的应用程序在 http 代理后面运行,则ninja.ninja.x_forwarded_for_enabled
必须在 application.conf 中将标志设置为true
负载均衡器。