0
我正在嘗試調用其他應用程序的安全REST服務。還提供了客戶端證書,但如下得到錯誤:節點JS 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,
..........
我試着用郵遞員,得到響應REST客戶端進行測試。 但不能通過上面的節點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配置設定了嚴格的SSL假」的命令,但不能工作。
我也試圖與 rejectUnauthorized:虛假和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>
我試過所有的可能性,但得到錯誤提及,請建議如果我錯過任何東西或需要更新任何東西。謝謝。