Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using proxy like fiddler with fetch api

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
like image 406
Lajos Avatar asked Jun 13 '17 14:06

Lajos


1 Answers

@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){
    //...
})
like image 138
serv-inc Avatar answered Sep 30 '22 04:09

serv-inc