在 fetch api 中使用类似 fiddler 的代理

Laj*_*jos 5 javascript proxy fiddler node.js fetch-api

如何使用 Fetch API 设置代理。我正在开发一个 node.js 应用程序,我想看看 HTTPS 响应的响应正文。我正在使用这个使用 node http 的 npm 包:https : //www.npmjs.com/package/isomorphic-fetch

我试图设置 env 变量,如:

set https_proxy=http://127.0.0.1:8888
set http_proxy=http://127.0.0.1:8888
set NODE_TLS_REJECT_UNAUTHORIZED=0
Run Code Online (Sandbox Code Playgroud)

但它似乎只适用于请求 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
Run Code Online (Sandbox Code Playgroud)

ser*_*inc 5

@jimliang 已经发布了一个解决方案node-fetch。他

使用https://github.com/TooTallNate/node-https-proxy-agent

fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')})
.then(function(res){
    //...
})
Run Code Online (Sandbox Code Playgroud)