【问题标题】:Using proxy like fiddler with fetch api使用像 fiddler 这样的代理和 fetch api
【发布时间】: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


【解决方案1】:

@jimlianghas posted a solution for 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){
    //...
})

【讨论】:

    猜你喜欢
    • 2011-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-23
    • 1970-01-01
    • 2012-06-09
    • 1970-01-01
    相关资源
    最近更新 更多