在Fetch API中使用像Fiddler这样的代理 [英] Using proxy like fiddler with fetch api
本文介绍了在Fetch API中使用像Fiddler这样的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Fetch API设置代理. 我正在开发一个node.js应用程序,我想看看HTTPS响应的响应主体.我正在使用在节点内部使用节点http的npm软件包: https://www.npmjs.com/package/isomorphic-fetch
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
但它似乎仅适用于请求NPM节点模块.
but it seems to work only with request NPM node module.
我总是收到以下消息:
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
推荐答案
@jimliang has posted a solution for node-fetch
. He
fetch('https://www.google.com',{ agent:new HttpsProxyAgent('http://127.0.0.1:8580')})
.then(function(res){
//...
})
这篇关于在Fetch API中使用像Fiddler这样的代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文