【发布时间】:2017-11-15 09:26:51
【问题描述】:
如何使用 Fetch API 设置代理。 我正在开发一个 node.js 应用程序,我想看看 HTTPS 响应的响应正文。我正在使用这个在内部使用节点 http 的 npm 包: https://www.npmjs.com/package/isomorphic-fetch
我尝试将环境变量设置为:
set https_proxy=http://127.0.0.1:8888
set http_proxy=http://127.0.0.1:8888
set NODE_TLS_REJECT_UNAUTHORIZED=0
但它似乎只适用于请求 NPM 节点模块。
我总是收到以下消息:
http://127.0.0.1:8888
(node:30044) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): FetchError: request to https://www.index.hu failed, reason: read ECONNRESET
【问题讨论】:
-
我建议使用node-fetch 打开一个错误,因为该变量会影响所有节点模块。
-
@Bergi:已经在node-fetch中实现,见github.com/bitinn/node-fetch#options
-
@serv-inc 哦,对,那是关于代理的,我以为问题出在
NODE_TLS_REJECT_UNAUTHORIZED
标签: javascript node.js proxy fiddler fetch-api