0
我试图在自定义身份验证检查后从Java REST调用的响应中下载PDF文件。通过REST服务通过Java中的“Content-Disposition”标题下载PDF文件
我可以看到下载的文件,但它是空文件。
下面是我的代码片段。
//Custom HTTPClient
HTTPAuthClient client = new HTTPAuthClient(url,username,password)
Request request = new Request(downloadURL); //I'm downloading file content of an URL.
Response response = client.executeGet(request);
String response1 = response.getResponseBody();
InputStream is = new ByteArrayInputStream(response.getBytes());
response.setContentType("Content-type",application/pdf); //here response is //javax.servlet.HttpServletResponse
response.setHeader("Content-Disposition","attachment;filename="myfile.pdf");
IOUtils.copy(is,response.getOutPutStream());
response.flushBuffer();
使用此代码我可以下载文件,但是当我打开文件并验证没有数据时。 作为响应主体的一部分,我也可以看到一些数据。
您能否帮我解决我犯的错误我尝试了很多选择,但没有找到解决方案。