axios 没有 return 完整数据

axios does not return the full data

axios.get(downloadUrl, Object.assign({}, this.tokens[token_nr].config, {responseType: stream}))
.then((response) => {
    console.log("HEADERS", response.headers)

    console.log(typeof response.data, "RESPONSE LENGTH", response.data.length)

    const decryptedBuffer = encryptionService.decrypt(Buffer.from(response.data), infos);

    resolve(decryptedBuffer);
})

这个axios请求应该给出一个mp3文件的数据。我之前通过请求包获得了它,它提供了一个 binary Buffer(使用 encoding: null 选项),我可以在 encryptionService.decrypt() 函数中使用它。

response.headers 中,我可以看到它提供与请求包相同的 content-length。但是当我打印 response.data 的长度时,它变短了。我尝试将 ArrayBuffer 和流作为我的 ResponseType。此外,离开 ResponseType 选项也无济于事。我应该怎么做才能获得完整内容。

一些日志:(不是全部headers)

HEADERS {
  'accept-ranges': 'bytes',
  'cache-control': 'public',
  'content-type': 'audio/mpeg',
  'content-length': '14175084',
  connection: 'close'
}
string RESPONSE LENGTH 13495410
CONFIG HEADERS {
  headers: {
    Accept: 'application/json, text/plain, */*',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36',
    'cache-control': 'max-age=0',
    'accept-language': 'en-US,en;q=0.9,en-US;q=0.8,en;q=0.7',
    'accept-charset': 'utf-8,ISO-8859-1;q=0.8,*;q=0.7',
    cookie: 'arl=XXXX',
    Connection: 'keep-alive',
    'Keep-Alive': 'timeout=1500, max=100',
    'Content-Type': 'text/plain;charset=UTF-8'
  },
}

创建请求时尝试传递以下 headers 连接,Keep-Alive。有时它会在完全收到响应之前关闭连接

   var axioRequest = await axios.create({
        baseURL: url,
        headers: {
            Connection: 'keep-alive',
            'Keep-Alive': 'timeout=1500, max=100'
        }
    });

已通过以下回答解决: https://disjoint.ca/til/2017/09/20/how-to-download-a-binary-file-using-axios/

我错过了 Content-Type header 和 {ResponseType: 'arraybuffer'}