接受用于 undici 获取的自签名证书

Vit*_*ali 6 javascript fetch node.js undici

如何使用自签名证书(来自 undici)fetch('https://localhost:8888')本地运行的 HTTP 服务器?fetch

Vit*_*ali 3

诀窍是使用setGlobalDispatchergetGlobalDispatcher可以用来抓取原始的以便以后恢复)。

\n
import {\n  fetch,\n  setGlobalDispatcher,\n  Agent,\n} from 'undici'\n\nsetGlobalDispatcher(new Agent({\n\xc2\xa0 connect: {\n\xc2\xa0 \xc2\xa0 rejectUnauthorized: false\n\xc2\xa0 }\n}))\n\nfetch('https://localhost:8888').then(...)\n
Run Code Online (Sandbox Code Playgroud)\n