【问题标题】:Question mark in value of @InjectLink is encoded as %3F. How to prevent this?@InjectLink 值中的问号被编码为 %3F。如何防止这种情况?
【发布时间】:2014-09-25 15:42:52
【问题描述】:

我使用 Jersey 的 Link Headers 功能来创建 HTTP 链接头:

@InjectLink(value="users/?orgId=12345&page=0",rel="first")

除了问号外运行良好 - 它以 %3F 编码,生成的 URL 如下所示: http://localhost:8080/app/users/%3ForgId=12345&page=0

我有什么方法可以防止编码并保留问号字符吗?

【问题讨论】:

    标签: java jersey link-header


    【解决方案1】:

    不适用于@InjectLink(value)。 URL参数构建应该被@InjectLink(method, bindings...)使用。

    例如:

    @InjectLink(
      resource = UserResource.class,
      method ="getUserById", 
      bindings ={@Binding(name = "orgId", value = "${instance.orgId}")},
      style =  Style.ABSOLUTE,
      ... )
    

    和目标泽西资源UserResource.java

    @Path("users/{orgId}") 
    public User getUserById(@PathParam("orgId") String orgId) {...}
    

    【讨论】:

      【解决方案2】:

      question mar 是为查询参数字符串编码的 url,所以在你的路径中有 %3 是正常的。尝试使用“绑定”或将@Queryparams 像这样How to force URIBuilder.path(...) to encode parameters like "%AD"? This method doesn't always encode parameters with percentage, correctly

      【讨论】:

        猜你喜欢
        • 2017-04-06
        • 1970-01-01
        • 2020-03-18
        • 1970-01-01
        • 1970-01-01
        • 2018-10-16
        • 2023-04-03
        • 2020-08-06
        • 2016-03-09
        相关资源
        最近更新 更多