duanemei2194 2018-08-01 13:20
浏览 442
已采纳

如何在请求中转义正斜杠以使url路由器将其视为uri参数的一部分?

I have following route mapping using gorilla/mux:

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

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.

Code that's capturing params is following:

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

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

  • 写回答

2条回答 默认 最新

  • dtrphb5597 2018-08-01 15:27
    关注

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

    router.Handle("/v1/data/{param:.*}", handler)
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料