![](/img/trans.png)
[英]beforeunload event and Content-Disposition=attachment
[英]Unpack a gzip file that is content-disposition: attachment
我得到了一个 api 的 url,当我在浏览器中访问该 url 并通过我的登录时,它将正确下载一个 zip 文件,其中包含我想要的数据的 JSON 文件。
如何通过使用 Node 获取此 JSON 来获取它?
当我这样打电话时
const data = await fetch(url, {
headers: {
Authorization: "Basic " + btoa(username + ":" + password)
}
});
我正确地收到了data.body和data.headers,但我正在寻找的 JSON 数据附近没有任何东西。
甚至可以对附加的文件进行 API 调用吗?
我的解决方案:
import request from "request";
import zlib from "zlib";
import concat from "concat-stream";
const btoa = (str) => Buffer.from(str).toString("base64");
request(url, {
headers: {
Authorization: "Basic " + btoa(username + ":" + password),
}})
.pipe(zlib.createGunzip())
.pipe(
concat((stringBuffer) => {
console.log(stringBuffer.toString()) // gives me the json I was looking for
})
);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.