我是球衣/JAX-RS 实施的新手。
请在下面找到我的球衣客户端代码来下载文件:
Client client = Client.create();
WebResource wr = client.resource("http://localhost:7070/upload-0.0.1-SNAPSHOT/rest/files/download");
Builder wb=wr.accept("application/json,application/pdf,text/plain,image/jpeg,application/xml,application/vnd.ms-excel");
ClientResponse clientResponse= wr.get(ClientResponse.class);
System.out.println(clientResponse.getStatus());
File res= clientResponse.getEntity(File.class);
File downloadfile = new File("C://Data/test/downloaded/testnew.pdf");
res.renameTo(downloadfile);
FileWriter fr = new FileWriter(res);
fr.flush();
我的服务器端代码是:
@Path("/download")
@GET
@Produces({"application/pdf","text/plain","image/jpeg","application/xml","application/vnd.ms-excel"})
public Response getFile()
{
File download = new File("C://Data/Test/downloaded/empty.pdf");
ResponseBuilder response = Response.ok((Object)download);
response.header("Content-Disposition", "attachment; filename=empty.pdf");
return response.build();
}
在我的客户端代码中,我得到的响应为 200 OK,但我无法将文件保存在硬盘上
在下面的行中,我提到了需要保存文件的路径和位置。
不知道这里出了什么问题,任何帮助将不胜感激。提前致谢!
File downloadfile = new File("C://Data/test/downloaded/testnew.pdf");