简体   繁体   English

泽西岛客户的错误要求

[英]Jersey client bad request

I have below client code: 我有以下客户端代码:

String filePath = "/testzip/123/TEST-test.zip";
target = mainTarget.path("file").path("{filePath}");
Invocation.Builder invocationBuilder =  target
                .resolveTemplate("filePath", filePath)
                .request(MediaType.APPLICATION_JSON).accept(MediaType.APPLICATION_OCTET_STREAM);

Response response = invocationBuilder.get();

Below is my server code: 下面是我的服务器代码:

@GET
@Path("{filePath}")
@Produces({MediaType.APPLICATION_OCTET_STREAM})
public Response get(@PathParam("filePath") String filePath) {
    File file = new File(filePath);
    return Response.status(Response.Status.OK).entity(file).build();
}

This client is throwing Bad Request exception while I send below filePath: 当我在filePath下面发送时,此客户端抛出Bad Request异常:

String filePath = "/testzip/123/TEST-test.zip";

But it is working fine when I send below filePath (simple string): 但是当我在filePath(简单字符串)下面发送时,它工作正常:

String filePath = "testzip";

I am not able to figure it out why it is not working when forward slash(/) is present in path parameters. 我无法弄清楚当路径参数中存在正斜杠(/)时为什么它不起作用。

I believe you cannot have / in a @PathParam by default. 我相信默认情况下, @PathParam不能包含/

EDIT Have a look here : Tomcat, JAX-RS, Jersey, @PathParam: how to pass dots and slashes? 编辑在这里看看: Tomcat,JAX-RS,Jersey,@ PathParam:如何传递点和斜杠?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM