gpt4 book ai didi

node.js - 具有基本身份验证的客户端 SSL POST 给出 DEPTH_ZERO_SELF_SIGNED_CERT 错误

转载 作者:太空宇宙 更新时间:2023-11-03 14:58:32 28 4
gpt4 key购买 nike

我正在尝试对具有自签名证书的 Web 服务器在 HTTPS 上执行 method=POST。我下载了服务器公共(public)证书并将路径放在发布选项中。但是我在第 47 行收到错误 [Error: DEPTH_ZERO_SELF_SIGNED_CERT]。HTTPS 上的 method=GET 对于具有自签名证书的 Web 服务器工作正常。我做错了什么?

var https = require('https');
var querystring = require('querystring');
var fs = require('fs');


console.log("Starting...");

var certFile = "self_signed_cert.pem"

function ssl_post() {
var username = "user";
var password = "password";

var post_data = '';
var basic = 'Basic ' + new Buffer(username + ':' + password).toString('base64');
// An object of options to indicate where to post to
var post_options = {
host: 'someservername',
port: 443,
path: '/add',
method: 'POST',
headers: {
'accept': '*/*',
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': post_data.length,
'Authorization': basic,
'ca': fs.readFileSync(certFile, 'utf8')
}
};
// Set up the request
var data = '';
var post_req = https.request(post_options, function(res) {
//res.setEncoding('utf8');
res.on('data', function(res) {
//res.setEncoding('utf8');
res.on('data', function(chunk) {
data += chunk;
});
res.on('end', function() {
console.log(data);
});
});
});
post_req.on('error', function(e) {
console.log(e);
});
// post the data
post_req.write(post_data);
post_req.end();
}


ssl_post();

console.log("Finished.");

最佳答案

您没有将ca 直接放入post_options,而是放入了headers 部分。但是,ca 不应用作 HTTP header ,因此请将其直接放入 post_options

关于node.js - 具有基本身份验证的客户端 SSL POST 给出 DEPTH_ZERO_SELF_SIGNED_CERT 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26008357/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com