2015-10-04 214 views
0

我有下面的客户端代码:Jersey客户端错误的请求

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"; 

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

String filePath = "testzip"; 

我无法弄清楚为什么当正斜杠(/)出现在路径参数中时它不工作。

+0

尝试,只是做'target.path(文件路径).reqest()'。为什么'MediaType.APPLICATION_JSON'?对请求资源没有多大意义。 –

+0

@peeskillet我已经移除了'MediaType.APPLICATION_JSON',因为它没有任何意义。 'target.path(filePath).reqest()'不适合我。它说“请求的资源不可用”。因为它会将某些资源路径作为正斜杠并试图在服务器端找到该资源 –

回答