编写程序以从 FAA 的 AIDAP 数据库中提取数据。他们向我发送了一个 .p12 文件形式的安全证书,我已将其转换为 .pem。寻找有关如何在我的代码中加载它的实现指南。当我运行我现在拥有的代码时,我只是得到“禁止访问”
var request = require('request');
request('https://www.aidap.naimes.faa.gov/aidap/XmlNotamServlet', function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body) // Show the HTML for the website
}
})
我正在使用 Request npm 包作为 http 客户端,还尝试了 xmlhttprequest,因为我需要的数据是 html。
注意:我只有安全证书和他们给我的用于登录证书的密码。当我使用安装在 Chrome 上的证书访问 Chrome 中的网站时,网站 url 有效。在我的 javacscript IDE 中,禁止访问。
寻找有关如何实现 .pem 证书的指导
最佳答案
试试这段代码:
var request = require('request');
var fs = require('fs');
var path = require('path');
var pemFile = path.resolve(__dirname, 'ssl/certificate.pem');
var options = {
url : 'https://www.aidap.naimes.faa.gov/aidap/XmlNotamServlet',
passphrase : 'password',
ca : fs.readFileSync(pemFile) //reading the pem file
};
request.get(options, function (error, response, body) {
if (!error && response.statusCode === 200) {
console.log(body); // Show the HTML for the website
}
});
关于使用 request
库的更多文档,关于这里的 TLS/SSL 协议(protocol):
关于javascript - 在 JavaScript 中使用 SSL 证书(pem 文件),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32513739/