【问题标题】:Get the ip address of the request in ninja frameworkninja框架中获取请求的ip地址
【发布时间】:2017-05-23 20:12:26
【问题描述】:

我的应用中有以下框架

Ninja, Akka, Spray

如何获取客户端请求的ip地址?

我的路由定义如下:

    router.GET.route(urlPrefix + "/method").`with`(classOf[Controller],"method")

【问题讨论】:

    标签: scala akka spray ninjaframework


    【解决方案1】:

    我不确定你的问题是指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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-02-01
      • 1970-01-01
      • 2010-10-26
      • 2015-08-31
      • 2013-05-31
      • 1970-01-01
      相关资源
      最近更新 更多