【发布时间】:2021-09-01 20:27:05
【问题描述】:
...
PdfWriter.getInstance(document, outputStream); // outputstream from java
我通过fetch api和postman成功下载了这个pdf文件,但是被axios下载失败了,虽然大小正常。
// I successfully downloaded this pdf file by fetch api and postman, but failed by axios, even though the size was normal(blank content).
axios({
url: `xxx`,
method: 'get',
responseType: 'arraybuffer'
}).then(resp => {
const url = window.URL.createObjectURL(new Blob([resp.data], {type:"application/pdf"}));
const link = document.createElement('a');
link.href = url;
link.setAttribute('download', 'test.pdf');
document.body.appendChild(link);
link.click();
})
有人可以帮我吗?
【问题讨论】:
-
这篇文章有什么见解吗?出于某种原因,我的敏感意识集中在 arraybuffer 和 application/pdf 上,但我真的不知道。 stackoverflow.com/questions/60454048/…
-
如果您将 arraybuffer 更改为流,就像在这个问题报告中一样? github.com/axios/axios/issues/1392
-
@DanChase 。我试过了,还是不行。
-
打开开发者工具,进入网络选项卡,然后再打开一次,你会得到 200 响应码吗?在 const url= 处设置断点,并将光标放在“resp”上。看看数据有没有什么。
-
@DanChase。代码是200,我发现axios返回的response.data和我postman请求服务器时的response是一样的。
标签: axios