在 Spray 路由指令中获取查询字符串
Get query string in Spray routing directive
我需要在路由指令中设置重定向:
path("old") {
params { p =>
redirect("http://newu.rl/foo?" + ???, StatusCodes.PermanentRedirect)
}
}
我能否获得客户端发送的准确查询字符串?或者我需要从参数 p
?
重建它
您可以使用 extract 创建自定义指令以从 uri 中检索查询字符串:
val queryString = extract(_.request.uri.query)
path("old") {
queryString { query =>
redirect("http://newu.rl/foo?" + query, StatusCodes.PermanentRedirect)
}
}
我需要在路由指令中设置重定向:
path("old") {
params { p =>
redirect("http://newu.rl/foo?" + ???, StatusCodes.PermanentRedirect)
}
}
我能否获得客户端发送的准确查询字符串?或者我需要从参数 p
?
您可以使用 extract 创建自定义指令以从 uri 中检索查询字符串:
val queryString = extract(_.request.uri.query)
path("old") {
queryString { query =>
redirect("http://newu.rl/foo?" + query, StatusCodes.PermanentRedirect)
}
}