我正试图将数据发送到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"
}
package-lock.json
{
"name": "qmyapp.com",
"version": "1.0.0",
"lockfileVersion": 1
}
请我如何正确地解决这个问题,也可以有人告诉我,如果这是发送一个帖子请求从节点js到php的正确方式。由于
p/S:如果你需要更多的解释,请问我快速但不安全
仅用于调试目的!process.env.NODE_TLS_REJECT_UNAUTHORIZED='0'
修复
更新php站点使用的证书的最佳方法https://github.com/skoerfgen/ACMECert