Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 如何使用fetch-in节点发出http请求?节点获取_Node.js_Fetch - Fatal编程技术网

Node.js 如何使用fetch-in节点发出http请求?节点获取

Node.js 如何使用fetch-in节点发出http请求?节点获取,node.js,fetch,Node.js,Fetch,我正试图在节点中发出请求。这是我的密码: fetch("http://www.test.com", options).catch(err => { console.error(err); return err; }); 这是我得到的错误。 TypeError:仅支持HTTP协议 我已尝试创建一个新代理,并将其传入如下选项: const httpAgent = new http.Agent({ keepAlive: true }); const httpsAg

我正试图在节点中发出请求。这是我的密码:

fetch("http://www.test.com", options).catch(err => {
    console.error(err);

    return err;
  });
这是我得到的错误。
TypeError:仅支持HTTP协议

我已尝试创建一个新代理,并将其传入如下选项:

const httpAgent = new http.Agent({
    keepAlive: true
});
const httpsAgent = new https.Agent({
    keepAlive: true
});

const options = {
    agent: function (_parsedURL) {
        if (_parsedURL.protocol == 'http:') {
            return httpAgent;
        } else {
            return httpsAgent;
        }
    }
}
我仍然会犯同样的错误

当我在客户端运行此操作时,我可以向同一个
获取
发送
http
https
请求,并且没有问题。显然,在节点上是不同的


最好的处理方法是什么?

这看起来很奇怪。你确定它被保存了吗?网页包重新编译了吗?节点是否需要重新启动?您确定错误是针对该行的吗?我自己也使用过
节点获取
很多,这应该可以用。我不知道,他们强制它是https