我如何通过 ssl、https Node.js 连接?
How can i connect via ssl, https Node.js?
请问,我如何通过 ssl、https Node.js 连接?这是我的代码:
var Client = require('node-rest-client').Client;
client = new Client();
var headers = {
//"Accept": "application/json",
"Authorization": "Bearer "+sails.config.myGlobalVariables.access_token,
};
var args = {
headers: headers,
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
client.get("https://localhost:9443/oauth2/userinfo?schema=openid", args, function(data,response) {
// parsed response body as js object
//console.log(data.clienteCollection.cliente); //Prueba de listado de clientes recorrer JSON
// raw response
//console.log(response);
//console.log(data.name);
//req.session.nombreCompleto = data.name;
//console.log(data);
res.view('index',{
nombreCompleto: data.name,
});
});
我正在使用库 node-rest-client 和 Sails.js。
我不想放置:process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
感谢您的帮助。
根据 node-rest-client and nodejs https.request 文档,您可以在创建新客户端时以 PEM 格式在选项哈希中传递您的 CA。因此,您必须使用链式证书。否则,您可以使用由 众所周知的 "root" CA 签名的证书,该证书受到 node.js.
的信任
new Client({
connection: {
ca: fs.readFileSync('ca.pem'),
}
});
如 this issue 中所述 node.js 不使用操作系统信任库,而是使用静态编译、手动更新、硬编码的证书颁发机构列表。
请问,我如何通过 ssl、https Node.js 连接?这是我的代码:
var Client = require('node-rest-client').Client;
client = new Client();
var headers = {
//"Accept": "application/json",
"Authorization": "Bearer "+sails.config.myGlobalVariables.access_token,
};
var args = {
headers: headers,
};
process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0";
client.get("https://localhost:9443/oauth2/userinfo?schema=openid", args, function(data,response) {
// parsed response body as js object
//console.log(data.clienteCollection.cliente); //Prueba de listado de clientes recorrer JSON
// raw response
//console.log(response);
//console.log(data.name);
//req.session.nombreCompleto = data.name;
//console.log(data);
res.view('index',{
nombreCompleto: data.name,
});
});
我正在使用库 node-rest-client 和 Sails.js。 我不想放置:process.env.NODE_TLS_REJECT_UNAUTHORIZED = "0"; 感谢您的帮助。
根据 node-rest-client and nodejs https.request 文档,您可以在创建新客户端时以 PEM 格式在选项哈希中传递您的 CA。因此,您必须使用链式证书。否则,您可以使用由 众所周知的 "root" CA 签名的证书,该证书受到 node.js.
的信任new Client({
connection: {
ca: fs.readFileSync('ca.pem'),
}
});
如 this issue 中所述 node.js 不使用操作系统信任库,而是使用静态编译、手动更新、硬编码的证书颁发机构列表。