使用 node-fetch 间歇性下载 json 失败

问题描述

我正在尝试从 API 下载 json 响应,但它失败了 10 次中的 9 次。

响应相当大 - 大约 90mb。在邮递员中下载,webbrowser 每次都可以工作,但在节点中,响应似乎被扭曲并且不是有效的 json。有时会奏效。

使用 node-fetch-2.6.1 尝试了 v16.1.0 和 v14.15.5

const fetch = require('node-fetch');

fetch('https://xxxxx',{ 
        headers: { 'Authorization': 'Basic xxxxxx',},})

   .then(res => res.json())
    .then(json => console.log(json));

有什么想法吗?

解决方法

node-fetch 中的疑似错误 - 使用 node-libcurl 解决。