【发布时间】:2017-11-24 17:50:31
【问题描述】:
我正在尝试调用其他应用程序的安全 REST 服务。还提供客户端证书,但出现如下错误:
request function
Response: IncomingMessage {
_readableState:
ReadableState {
objectMode: false,
highWaterMark: 16384,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
.........
authorized: false,
**authorizationError: 'SELF_SIGNED_CERT_IN_CHAIN',**
encrypted: true,
..........
我尝试使用邮递员与休息客户端进行测试并获得响应。 但无法通过上述 Node JS 程序/代码工作。 因此,据我了解,这是由于 SSL 拦截代理而发生的; npm 检测到这一点并抱怨。
我已经在 Node JS 应用程序中使用 POST 方法实现了 Rest 客户端来使用 REST 服务,如下所示。
var https = require('https');
var fs = require('fs');'
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
var options = {
host: '<HOSTNAME>',
port: '<PORT>',
path: '<PATH>',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json',
'Authorization': '',
},
ca: [ fs.readFileSync('<.jks file/ certificate name>') ],
checkServerIdentity: function (host, cert) {
},
rejectUnauthorized:false,
body: ''
};
var req = https.request(options, function(res) {
console.log('request function')
console.log("Response: ", res);
res.on('data', function(d) {
'' +
'?' });
});
req.end();
req.on('error', function(e) {
console.error(e);
});
我尝试了其他解决方案,例如 “npm config set strict-ssl false”命令但无法工作。
我也试过 拒绝未授权:假和 process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0" 正如您在我的代码中看到的,但到目前为止没有任何效果。
Few required entries in .npmrc file are as below:
registry=https://registry.npmjs.org/
strict-ssl=false
cafile= <certificate path>
我尝试了所有可能性,但出现上述错误,如果我遗漏了任何内容或需要更新任何内容,请提出建议。谢谢。
【问题讨论】:
标签: node.js rest npm ssl-certificate