在Fetch API中使用像Fiddler这样的代理

编程入门 行业动态 更新时间:2024-10-17 21:26:06
本文介绍了在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这样的代理

本文发布于:2023-11-14 19:55:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1588372.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Fetch   API   Fiddler

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!