日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時間:8:30-17:00
你可能遇到了下面的問題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
創(chuàng)新互聯(lián)Node.js教程:Node.jsHTTPS
穩(wěn)定性: 3 - 穩(wěn)定

HTTPS是什么?HTTPS是基于TLS/SSL的HTTP協(xié)議,在node.js里它可以作為單獨的模塊來實現(xiàn)。在本文中,你將了解HTTPS的使用方法。

目前創(chuàng)新互聯(lián)已為近1000家的企業(yè)提供了網(wǎng)站建設(shè)、域名、虛擬空間、網(wǎng)站托管、服務(wù)器租用、企業(yè)網(wǎng)站設(shè)計、荔浦網(wǎng)站維護(hù)等服務(wù),公司將堅持客戶導(dǎo)向、應(yīng)用為本的策略,正道將秉承"和諧、參與、激情"的文化,與客戶和合作伙伴齊心協(xié)力一起成長,共同發(fā)展。

類: https.Server

https.Server是tls.Server的子類,并且和http.Server一樣觸發(fā)事件。更多信息參見http.Server。

server.setTimeout(msecs, callback)

詳情參見http.Server#setTimeout().

server.timeout

詳情參見http.Server#timeout.

https.createServer(options[, requestListener])

返回一個新的HTTPS服務(wù)器對象。其中options類似于 [tls.createServer()][tls.md#tls_tls_createserver_options_secureconnectionlistener]。 requestListener函數(shù)自動加到'request'事件里。

例如:

// 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);

server.listen(port[, host][, backlog][, callback])

server.listen(path[, callback])

server.listen(handle[, callback])

詳情參見http.listen()。

server.close([callback])

詳情參見http.close()。

https.request(options, callback)

可以給安全web服務(wù)器發(fā)送請求。

options可以是一個對象或字符串。如果options是字符串,則會被url.parse()解析。

所有來自http.request()選項都是經(jī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);
});

option參數(shù)具有以下的值:

  • host: 請求的服務(wù)器域名或IP地址,默認(rèn):'localhost'
  • hostname: 用于支持url.parse()。hostname優(yōu)于host
  • port: 遠(yuǎn)程服務(wù)器端口。默認(rèn): 443。
  • method: 指定HTTP請求方法。默認(rèn):'GET'。
  • path: 請求路徑。默認(rèn):'/'。如果有查詢字符串,則需要包含。比如'/index.html?page=12'
  • headers: 包含請求頭的對象
  • auth: 用于計算認(rèn)證頭的基本認(rèn)證,即user:password
  • agent: 控制Agent的行為。當(dāng)使用了一個Agent的時候,請求將默認(rèn)為Connection: keep-alive??赡艿闹禐椋?
    • undefined (default): 在這個主機和端口上使用[global Agent][]
    • Agent object: 在Agent中顯式使用passed.
    • false: 選擇性停用連接池,默認(rèn)請求為:Connection: close

tls.connect()的參數(shù)也能指定。但是,globalAgent會忽略他們。

  • pfx: SSL使用的證書,私鑰,和證書Certificate,默認(rèn)為null.
  • key: SSL使用的私鑰. 默認(rèn)為null.
  • passphrase: 私鑰或pfx的口令字符串. 默認(rèn)為null.
  • cert: 所用公有x509證書. 默認(rèn)為null.
  • ca: 用于檢查遠(yuǎn)程主機的證書頒發(fā)機構(gòu)或包含一系列證書頒發(fā)機構(gòu)的數(shù)組。
  • ciphers: 描述要使用或排除的密碼的字符串,格式請參閱http://www.openssl.org/docs/apps/ciphers.html#CIPHER_LIST_FORMAT
  • rejectUnauthorized: 如為true則服務(wù)器證書會使用所給CA列表驗證。如果驗證失敗則會觸發(fā)error事件。驗證過程發(fā)生于連接層,在HTTP請求發(fā)送之前。默認(rèn)為true.
  • secureProtocol: 所用的SSL方法,比如TLSv1_method強制使用TLS version 1。可取值取決于您安裝的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) {
  ...
}

https.get(options, callback)

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);
});

類: https.Agent

HTTPS的Agent對象,和http.Agent類似。詳情參見https.request()。

https.globalAgent

所有HTTPS客戶端請求的https.Agent全局實例。


當(dāng)前名稱:創(chuàng)新互聯(lián)Node.js教程:Node.jsHTTPS
轉(zhuǎn)載注明:http://m.5511xx.com/article/djhddgg.html