接受Undici Fetth的自我签名证书
如何进行 fetch('https:// localhost:8888')
对于本地运行的http服务器( fetch
来自UNDICI)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
如何进行 fetch('https:// localhost:8888')
对于本地运行的http服务器( fetch
来自UNDICI)?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
诀窍是使用
setGlobaldisPatcher
(getGlobaldisPatcher
可以用于抓住原始的以供以后修复)。The trick is to use
setGlobalDispatcher
(getGlobalDispatcher
can be used to grab the original one for later restoration).如果您使用的是node.js的内置
fetch
,则可以在初始化选项中指定dispatcher
。您仍然需要安装
UNDICI
(NPM安装UNDICI
)才能使用自定义agent
。If you are using Node.js's built-in
fetch
, you can specify thedispatcher
in the init options.You still need to install
undici
(npm install undici
) to be able to use a customAgent
.提示使用
vellyunauthorization的答案的问题:false
是,这使请求变得不安全。我建议您从您要尝试到的服务器/网站获得PEM Base64'd证书,并在提出请求时通过代理包含它:
您可以通过访问https:// localhost:8888通过您的浏览器,单击URL旁边的“安全”/锁定图标,然后遵循浏览器的步骤,将证书下载为CRT或PEM。将其作为纯文本打开以检验base64含量。
或通过命令行导出它,但是您必须自己将其从CER转换为Base64格式。
另外,您也可以在计算机上安装证书,您可能不必完全担心此证书。
The issue with answers that suggest using
rejectUnauthorized: false
is that this makes the request unsecure.I'd suggest you get the PEM base64'd certificate from the server/site you're trying to reach and include it through an agent when making your request:
You can get the base64 certificate by accessing https://localhost:8888 through your browser, clicking on the "secure"/lock icon next to the URL and following your browser's steps to download the certificate as CRT or PEM. Open it as plain text to retrive the base64 content.
Or export it via command line, but you'll have to convert it from CER to base64 format yourself.
Alternatively, you can also install the certificate on your machine and you may not have to worry about this altogether.
您也可以使用前类。近视类具有options.requesttls and options.proxytls,在文档中未描述。为了使用venuctunauthorizatization:false选项,只有以下代码:
还检查测试用例通过http到https endpoint 和代理和proxy-agent 源代码。这是
You can also use the ProxyAgent class. The ProxyAgent class has an options.requestTls and options.proxyTls, which are not described in document. In order to use rejectUnauthorized : false options, just code like below:
Also check the test case Proxy via HTTP to HTTPS endpoint and the proxy-agent source code.This is the fixed pr