Using proxy like fiddler with fetch api

只愿长相守 提交于 2020-01-21 11:39:28

问题


How can I set a proxy using Fetch API. I'm developing a node.js application and I'd like to have a look at the response body of an HTTPS response. I'm using this npm package that uses node http inside: https://www.npmjs.com/package/isomorphic-fetch

I tried to set the env variables like:

set https_proxy=http://127.0.0.1:8888
set http_proxy=http://127.0.0.1:8888
set NODE_TLS_REJECT_UNAUTHORIZED=0

but it seems to work only with request NPM node module.

I always get the following message:

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

回答1:


@jimliang has posted a solution for node-fetch. He

used 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){
    //...
})


来源:https://stackoverflow.com/questions/44524236/using-proxy-like-fiddler-with-fetch-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!