泽西客户端请求不好

时间:2015-10-04 06:42:38

标签: java rest jersey jax-rs

我有以下客户代码:

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();

以下是我的服务器代码:

@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();
}

当我发送下面的filePath时,这个客户端抛出Bad Request异常:

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

但是当我发送下面的filePath(简单字符串)时它工作正常:

String filePath = "testzip";

当路径参数中存在正斜杠(/)时,我无法弄清楚为什么它不起作用。

1 个答案:

答案 0 :(得分:1)

我认为默认情况下/不能@PathParam

编辑看看这里:Tomcat, JAX-RS, Jersey, @PathParam: how to pass dots and slashes?

相关问题