【问题标题】:URI Template variable containing a path?包含路径的 URI 模板变量?
【发布时间】:2012-01-19 04:18:25
【问题描述】:

我有一个关于 URI 模板变量的问题。

我需要使用以下形式管理 URI:

http://netlocation:port/application_path/{variable}

变量本身可以是路径,例如

this/variable/is/a/path

使完整的 URI 看起来是

http://netlocation:port/application_path/this/variable/is/a/path

我该如何管理?

【问题讨论】:

    标签: java http rest uri uritemplate


    【解决方案1】:

    使用“+”运算符以避免转义“/”字符:

    http://netlocation:port/application_path/{+foo}
    

    你可以试试URI Template Parser Online

    【讨论】:

    • 这是我的解决方案。
    【解决方案2】:

    您可以使用查询参数并以标准方式对路径变量进行编码:

    http://netlocation:port/application_path?path=%2Fthis%2Fvariable%2Fisapath
    

    【讨论】:

      【解决方案3】:
      猜你喜欢
      • 1970-01-01
      • 2020-01-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多