【发布时间】:2015-10-04 15:11:41
【问题描述】:
我有以下客户端代码:
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();
}
当我在文件路径下发送时,此客户端抛出错误请求异常:
String filePath = "/testzip/123/TEST-test.zip";
但是当我发送到下面的文件路径(简单字符串)时它工作正常:
String filePath = "testzip";
当路径参数中存在正斜杠(/)时,我无法弄清楚为什么它不起作用。
【问题讨论】:
-
试着做
target.path(filePath).reqest()。为什么MediaType.APPLICATION_JSON?对请求资源没有多大意义。 -
@peeskillet 我删除了
MediaType.APPLICATION_JSON,因为它没有意义。target.path(filePath).reqest()对我不起作用。它说“请求的资源不可用。”因为它将斜杠作为一些资源路径并试图在服务器端找出该资源