[英]Node - Unable to Verify the First Certificate / UNABLE_TO_VERIFY_LEAF_SIGNATURE localhost
I have an ASP.NET Core 3.1 web app that I run on my local development machine.我有一个在本地开发机器上运行的 ASP.NET Core 3.1 Web 应用程序。 This app successfully runs.此应用程序成功运行。 I can also successfully execute requests to it via Postman.我也可以通过 Postman 成功执行对它的请求。 I'm trying to run a test from a Node.js app.我正在尝试从 Node.js 应用程序运行测试。 This app is using Axios to try to load one of the web pages.此应用程序正在使用Axios尝试加载其中一个网页。 The request looks like this:请求如下所示:
const result = await axios.get('https://localhost:5001/');
When this request runs, I receive the following error:当此请求运行时,我收到以下错误:
Error: unable to verify the first certificate
...
code: 'UNABLE_TO_VERIFY_LEAF_SIGNATURE',
...
The fact that I can a) load the url in my browser and b) run the request from Postman leads me to believe there is a config issue with my Node app.我可以 a) 在浏览器中加载 url 和 b) 运行来自 Postman 的请求这一事实让我相信我的 Node 应用程序存在配置问题。 I don't know if it's an issue with a) my axios
request or b) some app configuration.我不知道这是否是 a) 我的axios
请求或 b) 某些应用程序配置的问题。 Oddly, I receive the same error if I try to execute my request against http://localhost:5000/
(ie not over HTTPS).奇怪的是,如果我尝试针对http://localhost:5000/
(即不通过 HTTPS)执行我的请求,我会收到同样的错误。
I'm unsure how to resolve this issue though.我不确定如何解决这个问题。 How do I execute a request via Axios against a web app running on localhost?如何通过 Axios 针对本地主机上运行的 Web 应用程序执行请求?
You'll need to tell axios/node what signing authorities to trust (your browser and postman will already have several of those set up)您需要告诉 axios/node 信任哪些签名机构(您的浏览器和邮递员已经设置了其中的几个)
You do that by configuring the https agent in axios - have a look at this answer for an example : How to configure axios to use SSL certificate?您可以通过在 axios 中配置 https 代理来实现这一点 - 以这个答案为例: 如何配置 axios 以使用 SSL 证书?
And here are instructions on how to get the bundle from the browser (you'll probably need to use a p7b/pfx or get all certs in the chain): https://medium.com/@menakajain/export-download-ssl-certificate-from-server-site-url-bcfc41ea46a2以下是有关如何从浏览器获取捆绑包的说明(您可能需要使用 p7b/pfx 或获取链中的所有证书): https : //medium.com/@menakajain/export-download-ssl -certificate-from-server-site-url-bcfc41ea46a2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.