简体   繁体   中英

Node: Error: unable to verify the first certificate when trying to reach ASP.NET Core app

I have an ASP.NET Core app running on my local machine. I'm trying to test that app via some code I wrote in Node.js. In that code, I'm using Axios. The following code generates an error that says: "Unable to verify the first certificate". The code is this:

let result = await axios.get('https://localhost:5001/');

I have seen several solutions posted on SO, however, none explain the issue. I don't understand 1) what's safe (we're dealing with certificates here) and 2) where the change needs to be made (ie in the Node app or in the ASP.NET Core app, or even changes on both sides).

How do I safely allow Node.js to access the ASP.NET Core app running locally on my machine?

Thank you!

ASP.NET Core will be using a self-signed certificate after installing it. Since it is self-signed, there is no reason for it to be trusted. And you need to trust it manually or suppress this error. (Which means you need to accept untrusted certificates while requesting)

Since in production environment, you can use your own certificate which might from a trusted provider like Let's encrypt, you don't need to worry about that issue.

Questions:

  1. what's safe (we're dealing with certificates here)

"Safe" for the HTTPS means that it needs to verify the server-side certificate is always trusted.

  1. where the change needs to be made (ie in the Node app or in the ASP.NET Core app, or even changes on both sides).

No there doesn't need to change anything. Just trust the self-signed certificate is fine.


To trust the certificate run 'dotnet dev-certs https --trust' (Windows and macOS only).

Learn about HTTPS: https://aka.ms/dotnet-https

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM