HTTPS 是建立在 TLS/SSL 之上的 HTTP 協(xié)議。在io.js中,它被作為單獨模塊實現(xiàn)。
這個類是tls.Server的子類,并且和http.Server觸發(fā)相同的事件。更多信息請參閱http.Server。
參閱http.Server#setTimeout()。
參閱http.Server#timeout。
返回一個新的 HTTPS web 服務(wù)器對象。options與tls.createServer()中的類似。requestListener會被自動添加為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()。
向一個安全 web 服務(wù)器發(fā)送請求。
options可以是一個對象或一個字符串。如果options是一個字符串,它會自動被url.parse()解析。
所有的http.request()選項都是可用的。
例子:
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ù)有以下選項:
localhost。host的別名。為了支持url.parse()的話,hostname比host更好些。host和hostname時的 IP 地址協(xié)議族。合法值是4和6。當(dāng)沒有指定時,將都被使用。80。socket(使用host:port或socketPath)。GET。/。如果有查詢字符串,則需要包含。例如'/index.html?page=12'。請求路徑包含非法字符時拋出異常。目前,只否決空格,不過在未來可能改變。'user:password'。agent行為。當(dāng)使用一個代理時,請求將默認(rèn)為Connection: keep-alive??赡苤涤校?agent中顯示使用 passed。agent的連接池。默認(rèn)請求為Connection: close。以下來自tls.connect()的選項也可以被指定。但是,一個globalAgent會默默忽略這些。
null。null。null。null。http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT。true,服務(wù)器證書會使用所給的 CA 列表驗證。驗證失敗時,一個error事件會被觸發(fā)。驗證發(fā)生于連接層,在 HTTP 請求發(fā)送之前。默認(rèn)為true。SSLv3_method強(qiáng)制使用 SSL v3??捎玫闹等Q你的OpenSSL安裝和SSL_METHODS常量。要指定這些選項,使用一個自定義的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可以是一個對象或一個字符串。如果options是一個字符串,它會自動被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);
});
一個與http.Agent類似的 HTTPS Agent對象。更多信息請參閱https.request()。
所有 HTTPS 客戶端請求的全局https.Agent實例。