如何在请求中转义正斜杠以使url路由器将其视为uri参数的一部分? [英] How to escape forward slash in request to make url-routers count it as part of uri parameter?

查看:201
本文介绍了如何在请求中转义正斜杠以使url路由器将其视为uri参数的一部分?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用大猩猩/ mux 进行以下路线映射:

I have following route mapping using gorilla/mux:

router.Handle("/v1/data/{param}", handler)

当我呼叫 curl http:// localhost:8080 / v1 / data / hello%2Fworld 我得到 404 响应代码。问题是在我的微服务中,我想将 / v1 / data / 之后的所有内容解释为 param

when I call curl http://localhost:8080/v1/data/hello%2Fworld I get 404 response code. The problem is that in my microservice I would like to interpret everything that goes after /v1/data/ as param.

捕获参数的代码如下:

uriP := mux.Vars(r)
param := uriP["param"]

是否可能要使用 gorilla / mux 或任何其他路由器来实现此目的?

Is it possible to achieve this using gorilla/mux or any other router?

推荐答案

您应添加regexp,bc默认regexp匹配到 / 符号。

You should add regexp, bc default regexp is matching until / or ? symbols.

router.Handle("/v1/data/{param:.*}", handler)

这篇关于如何在请求中转义正斜杠以使url路由器将其视为uri参数的一部分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆