【发布时间】:2017-05-23 20:12:26
【问题描述】:
我的应用中有以下框架
Ninja, Akka, Spray
如何获取客户端请求的ip地址?
我的路由定义如下:
router.GET.route(urlPrefix + "/method").`with`(classOf[Controller],"method")
【问题讨论】:
标签: scala akka spray ninjaframework
我的应用中有以下框架
Ninja, Akka, Spray
如何获取客户端请求的ip地址?
我的路由定义如下:
router.GET.route(urlPrefix + "/method").`with`(classOf[Controller],"method")
【问题讨论】:
标签: scala akka spray ninjaframework
我不确定你的问题是指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 代理或负载平衡器后面运行,您必须在 application.conf 中将 ninja.ninja.x_forwarded_for_enabled 标志设置为 true。
【讨论】: