HTTPS 是建立在 TLS/SSL 之上的 HTTP 協(xié)議。在io.js中,它被作為單獨(dú)模塊實(shí)現(xiàn)。
這個(gè)類是tls.Server的子類,并且和http.Server觸發(fā)相同的事件。更多信息請(qǐng)參閱http.Server。
參閱http.Server#setTimeout()。
參閱http.Server#timeout。
返回一個(gè)新的 HTTPS web 服務(wù)器對(duì)象。options與tls.createServer()中的類似。requestListener會(huì)被自動(dòng)添加為request事件的監(jiān)聽器。
例子:
// curl -k https://localhost:8000/
var https = require('https');
var fs = require('fs');
var options = {
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
或
var https = require('https');
var fs = require('fs');
var options = {
pfx: fs.readFileSync('server.pfx')
};
https.createServer(options, function (req, res) {
res.writeHead(200);
res.end("hello world\n");
}).listen(8000);
詳情參閱http.listen()。
詳情參閱http.close()。
向一個(gè)安全 web 服務(wù)器發(fā)送請(qǐng)求。
options可以是一個(gè)對(duì)象或一個(gè)字符串。如果options是一個(gè)字符串,它會(huì)自動(dòng)被url.parse()解析。
所有的http.request()選項(xiàng)都是可用的。
例子:
var https = require('https');
var options = {
hostname: 'encrypted.google.com',
port: 443,
path: '/',
method: 'GET'
};
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
options參數(shù)有以下選項(xiàng):
localhost。host的別名。為了支持url.parse()的話,hostname比host更好些。host和hostname時(shí)的 IP 地址協(xié)議族。合法值是4和6。當(dāng)沒有指定時(shí),將都被使用。80。socket(使用host:port或socketPath)。GET。/。如果有查詢字符串,則需要包含。例如'/index.html?page=12'。請(qǐng)求路徑包含非法字符時(shí)拋出異常。目前,只否決空格,不過在未來可能改變。'user:password'。agent行為。當(dāng)使用一個(gè)代理時(shí),請(qǐng)求將默認(rèn)為Connection: keep-alive??赡苤涤校?agent中顯示使用 passed。agent的連接池。默認(rèn)請(qǐng)求為Connection: close。以下來自tls.connect()的選項(xiàng)也可以被指定。但是,一個(gè)globalAgent會(huì)默默忽略這些。
null。null。null。null。http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT。true,服務(wù)器證書會(huì)使用所給的 CA 列表驗(yàn)證。驗(yàn)證失敗時(shí),一個(gè)error事件會(huì)被觸發(fā)。驗(yàn)證發(fā)生于連接層,在 HTTP 請(qǐng)求發(fā)送之前。默認(rèn)為true。SSLv3_method強(qiáng)制使用 SSL v3??捎玫闹等Q你的OpenSSL安裝和SSL_METHODS常量。要指定這些選項(xiàng),使用一個(gè)自定義的Agent。
例子:
var options = {
hostname: 'encrypted.google.com',
port: 443,
path: '/',
method: 'GET',
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem')
};
options.agent = new https.Agent(options);
var req = https.request(options, function(res) {
...
}
或不使用Agent。
例子:
var options = {
hostname: 'encrypted.google.com',
port: 443,
path: '/',
method: 'GET',
key: fs.readFileSync('test/fixtures/keys/agent2-key.pem'),
cert: fs.readFileSync('test/fixtures/keys/agent2-cert.pem'),
agent: false
};
var req = https.request(options, function(res) {
...
}
類似于http.get(),但是使用 HTTPS。
options可以是一個(gè)對(duì)象或一個(gè)字符串。如果options是一個(gè)字符串,它會(huì)自動(dòng)被url.parse()解析。
例子:
var https = require('https');
https.get('https://encrypted.google.com/', function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
process.stdout.write(d);
});
}).on('error', function(e) {
console.error(e);
});
一個(gè)與http.Agent類似的 HTTPS Agent對(duì)象。更多信息請(qǐng)參閱https.request()。
所有 HTTPS 客戶端請(qǐng)求的全局https.Agent實(shí)例。