【问题标题】:Get query string in Spray routing directive在 Spray 路由指令中获取查询字符串
【发布时间】:2015-09-15 21:35:34
【问题描述】:

我需要在我的路由指令中设置重定向:

path("old") {
  params { p =>
    redirect("http://newu.rl/foo?" + ???, StatusCodes.PermanentRedirect)
  }
}

我可以得到客户端发送的确切查询字符串吗?还是我需要从参数p重构它?

【问题讨论】:

    标签: scala spray


    【解决方案1】:

    您可以使用extract 创建自定义指令以从 uri 中检索查询字符串:

    val queryString = extract(_.request.uri.query)
    path("old") {
      queryString { query =>
        redirect("http://newu.rl/foo?" + query, StatusCodes.PermanentRedirect)
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2015-10-25
      • 1970-01-01
      • 1970-01-01
      • 2015-04-12
      • 2011-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多