[英]Jersey client bad request
我有以下客户端代码:
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";
我无法弄清楚当路径参数中存在正斜杠(/)时为什么它不起作用。
我相信默认情况下, @PathParam
不能包含/
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.