RestTemplate请求接口返回PDF数据,如下面第二段,生成pdf无法打开,请问代码有啥问题吗,或者有别的实现方式
RestTemplate client = new RestTemplate();
String url = "接口地址";
ResponseEntity response = client.postForEntity(url, requertXml, String.class);
String rs = response.getBody().toString();
System.out.println(rs);
BufferedOutputStream bos = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream("G:\\temp\\data.pdf");
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bos = new BufferedOutputStream(fos);
try {
bos.write(rs.getBytes());
bos.close();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
%PDF-1.4
中间省略
<</Root 59 0 R/Prev 548069/ID [<17e73f673b8c9ec03dd54ad7b2d26a39><aa37e40b3fc5f15a1834d45d4a77c051>]/Encrypt 60 0 R/Info 1 0 R/Size 70>>
%iText-5.5.1
startxref
568719
%%EOF
%PDF-1.4
这个开头就说明你的字节流就是pdf了
设置下content-type看看,把下载的文件另存为修改后缀为pdf
博主您好!我遇到了相同的问题,请问您解决了吗
我用你这个方法写的,但是pdf文件里面啥内容没有,是什么问题呢