本文介绍了在Fetch API中使用像Fiddler这样的代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用Fetch API设置代理. 我正在开发一个node.js应用程序,我想看看HTTPS响应的响应主体.我正在使用在节点内部使用节点http的npm软件包: www.npmjs/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: www.npmjs/package/isomorphic-fetch
我试图将环境变量设置为:
I tried to set the env variables like:
set https_proxy=127.0.0.1:8888 set http_proxy=127.0.0.1:8888 set NODE_TLS_REJECT_UNAUTHORIZED=0但它似乎仅适用于请求NPM节点模块.
but it seems to work only with request NPM node module.
我总是收到以下消息:
127.0.0.1:8888 (node:30044) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): FetchError: request to www.index.hu failed, reason: read ECONNRESET推荐答案
@jimliang 发布了node-fetch 的解决方案.他
@jimliang has posted a solution for node-fetch. He
使用 github/TooTallNate/node-https-proxy-agent
fetch('www.google',{ agent:new HttpsProxyAgent('127.0.0.1:8580')}) .then(function(res){ //... })
更多推荐
在Fetch API中使用像Fiddler这样的代理
发布评论