CERT_HAS_EXPIRED - 在 post 从节点 js 请求到 php

CERT_HAS_EXPIRED - in post request to php from node js

我正在尝试将数据发送到 php 脚本,然后该脚本将保存在数据库中。但我收到一条错误消息 CERT_HAS_EXPIRED 今天是我第一次使用 node.js 这是我的 node.js 代码

const https = require("https");
const qs = require("querystring");

var postData = qs.stringify({
  name: "Bright Isaac",
  age: "21",
});

var options = {
  hostname: "localhost",
  port: 443,
  path: "/quelib/src/chats/post.php",
  method: "POST",
  headers: {
    "Content-Type": "application/x-www-form-urlencoded",
    "Content-Length": postData.length,
  },
};

var req = https.request(options, (res) => {
  console.log("statusCode:", res.statusCode);
  console.log("headers:", res.headers);

  res.on("data", (d) => {
    process.stdout.write(d);
  });
});

req.on("error", (e) => {
  console.error(e);
});

req.write(postData);
req.end();

错误

$ node index.js
Error: certificate has expired
    at TLSSocket.onConnectSecure (_tls_wrap.js:1497:34)
    at TLSSocket.emit (events.js:315:20)
    at TLSSocket._finishInit (_tls_wrap.js:932:8)
    at TLSWrap.ssl.onhandshakedone (_tls_wrap.js:706:12) {
  code: 'CERT_HAS_EXPIRED'

package.json

{
  "name": "qmyapp.com",
  "version": "1.0.0",
  "description": "chat",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "Bright Isaac",
  "license": "ISC"
}

包-lock.json

{
  "name": "qmyapp.com",
  "version": "1.0.0",
  "lockfileVersion": 1
}

请问我该如何正确解决这个问题,还有谁能告诉我这是否是从节点 js 向 php 发送 post 请求的正确方法。谢谢

P/S: 如果需要更多解释请问我

快速但不安全

仅用于调试目的!

process.env.NODE_TLS_REJECT_UNAUTHORIZED='0'

最佳修复方法

更新 php 站点的证书使用

https://github.com/skoerfgen/ACMECert