【问题标题】:URL is truncated after semicolon while requesting @pathParam In REST在 REST 中请求 @pathParam 时,URL 在分号后被截断
【发布时间】:2016-12-22 00:00:45
【问题描述】:

在 javascript 中,我正在对路径进行编码并附加到 URL。在 GET 调用中,REST URL 在分号后被截断。

路径名: !#;@$^&()_+{}:,.'[]

encodeURI(路径名): %21%23%3B%40%24%5E%26%28%29_%2B%7B%7D%3A%2C.%27%5B%5D

网址+路径: ../reports/SMC-%21%23%3B%40%24%5E%26%28%29_%2B%7B%7D%3A%2C.%27%5B%5D/configs?_=1482329220060

@GET
    @Path("/{report_name}/configs")
    @Produces({ MediaType.APPLICATION_JSON })
    @ApiOperation(value = "Fetches the configurations of the report",httpMethod = HttpMethod.GET, response = ReportConfigOptions.class)
    public Response getAllConfigOptions(@PathParam("report_name") String fqReportName,
            @QueryParam("context_parameters") ReportContextParameters contextParameters,
            @QueryParam("apply_locale") boolean applyLocale) {
@PathParam("report_name") String fqReportName 
....

fqReportName 将在分号 (;) 之后被截断 fqReportName : !#

是否可以阻止这种传输?

【问题讨论】:

    标签: java rest jersey


    【解决方案1】:

    问题是 jersy 正在考虑;作为矩阵参数指示。 看到这个答案: How can I map semicolon-separated PathParams in Jersey?

    编辑:

    这对我有用:

    @GET
    @Path("s/{s: .*}")
    @Produces("application/json")
    public Response s(@PathParam("s") String s){
        return Response.ok(s).build();
    
    }
    

    您可能需要优化您的正则表达式以不包含“/”,因为您在路径参数之后有第二个路径段。

    【讨论】:

    • 但我不想用分号分隔,我想要@pathParam 中的路径。
    猜你喜欢
    • 2012-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-07
    • 2021-10-20
    • 1970-01-01
    相关资源
    最近更新 更多