最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting SELF_SIGNED_CERT_IN_CHAIN error in axios, but passes via curl or postman - Stack Overflow

programmeradmin1浏览0评论

I am making an axios call to an endpoint which has been giving me 'SELF_SIGNED_CERT_IN_CHAIN' authorization error. When I make the same request via Postman, it works. Also, when I send the same request via curl, it works. I read up on other posts to set 'NODE_TLS_REJECT_UNAUTHORIZED' to '0', but that didn't help. I also found some posts where they said that this is associated to npm and to upgrade it, but that didn't help either.

Here's my axios call:

const response = await axios({
          method: 'post,
          url: 'https://some-test-url:port#123',
          data: { hello: 'world' },
          agentOptions: new https.Agent({
            key: fs.readFileSync("./key-file.key", 'utf8'),
            cert: fs.readFileSync("./cert-file.pem", 'utf8'),
            rejectUnauthorized: false,
            keepAlive: false,
          })
        });

Here's my curl request:

    curl https://some-test-url:port#123 -X POST -k -v --cert ./cert-file.pem  --key ./key-file.key -d '{"hello": "world"}' -H 'Content-Type: application/json'

Here's the error I'm getting:

'<html>\r\n<head><title>400 No required SSL certificate was sent</title></head>\r\n<body bgcolor="white">\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>No required SSL certificate was sent</center>\r\n<hr><center>openresty/1.13.6.1</center>\r\n</body>\r\n</html>\r\n'

Any ideas what I am I missing?

I am making an axios call to an endpoint which has been giving me 'SELF_SIGNED_CERT_IN_CHAIN' authorization error. When I make the same request via Postman, it works. Also, when I send the same request via curl, it works. I read up on other posts to set 'NODE_TLS_REJECT_UNAUTHORIZED' to '0', but that didn't help. I also found some posts where they said that this is associated to npm and to upgrade it, but that didn't help either.

Here's my axios call:

const response = await axios({
          method: 'post,
          url: 'https://some-test-url:port#123',
          data: { hello: 'world' },
          agentOptions: new https.Agent({
            key: fs.readFileSync("./key-file.key", 'utf8'),
            cert: fs.readFileSync("./cert-file.pem", 'utf8'),
            rejectUnauthorized: false,
            keepAlive: false,
          })
        });

Here's my curl request:

    curl https://some-test-url:port#123 -X POST -k -v --cert ./cert-file.pem  --key ./key-file.key -d '{"hello": "world"}' -H 'Content-Type: application/json'

Here's the error I'm getting:

'<html>\r\n<head><title>400 No required SSL certificate was sent</title></head>\r\n<body bgcolor="white">\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>No required SSL certificate was sent</center>\r\n<hr><center>openresty/1.13.6.1</center>\r\n</body>\r\n</html>\r\n'

Any ideas what I am I missing?

Share Improve this question asked Jan 24, 2020 at 13:58 MonaMona 3181 gold badge3 silver badges15 bronze badges 1
  • I have this exact same problem. Were you able to solve it? – TinkerTenorSoftwareGuy Commented Nov 24, 2020 at 2:49
Add a ment  | 

1 Answer 1

Reset to default 2

You can see the answer here: nodejs - error self signed certificate in certificate chain

Just simple set the environment variable then it will fix:

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = 0;

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论