多多色-多人伦交性欧美在线观看-多人伦精品一区二区三区视频-多色视频-免费黄色视屏网站-免费黄色在线

中國最全IT社區平臺 聯系我們 | 收藏本站
阿里云優惠2

nodejs教程

Node.js HTTPS

閱讀 (2218)

HTTPS

穩定性: 3 - 穩定

HTTPS 是基于 TLS/SSL 的 HTTP 協議。在 Node 里作為單獨的模塊來實現。

類: https.Server

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

server.setTimeout(msecs, callback)

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

server.timeout

詳情參見 http.Server#timeout.

https.createServer(options[, requestListener])

返回一個新的 HTTPS 服務器對象。其中 options 類似于 [tls.createServer()][tls.md#tls_tls_createserver_options_secureconnectionlistener]。 requestListener 函數自動加到 '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 服務器。

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

option 參數有以下的值:

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

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

  • pfx: SSL 使用的證書,私鑰,和證書Certificate, 默認 null.
  • key: SSL 使用的私鑰. 默認 null.
  • passphrase: 私鑰或 pfx 的口令字符串. 默認 null.
  • cert: 所用公有 x509 證書. 默認 null.
  • ca: 用于檢查遠程主機的證書頒發機構或包含一系列證書頒發機構的數組。
  • ciphers: 描述要使用或排除的密碼的字符串,格式請參閱http://www.openssl.org/docs/apps/ciphers.html
  • rejectUnauthorized: 如為 true 則服務器證書會使用所給 CA 列表驗證。如果驗證失敗則會觸發 error 事件。驗證過程發生于連接層,在 HTTP 請求發送之前。缺省為 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 全局實例。

關閉
程序員人生
主站蜘蛛池模板: 最新国产福利在线 | 热久久国产欧美一区二区精品 | linode日本iphone强汉 | xxx69欧美hdxxxhd | 亚洲精品国产成人99久久 | 国产日韩一区二区三区在线观看 | 综合图 | 麻豆成人在线 | 国产成人精品福利网站在线 | 自拍偷拍第一页 | 久九色 | 亚洲高清视频一区 | 欧美一级在线视频 | 欧美曰韩一区二区三区 | 日本一区二区高清 | 久久综合九色综合欧美就去吻 | 亚洲作爱视频 | 久久久久国产一级毛片高清片 | 久久精品亚洲一区二区 | 自拍欧美日韩 | aⅴ免费在线观看 | 激情视频网 | 欧美色啪 | 天天做天天爱天天大综合 | 国产成人综合洲欧美在线 | 在线免费观看污片 | jlzzjlzz亚洲大全 | 欧美精品首页 | freexxx性亚洲xxxx | 男女男精品视频在线观看 | 大学生一一级毛片在线播放 | 最近完整中文字幕1 | 精品亚洲综合久久中文字幕 | 精品无码久久久久久久动漫 | 精品久久久久久久高清 | 麻豆免费版在线观看 | 欧美性色黄大片www喷水 | 欧美亚洲 尤物久久 综合精品 | 色www永久免费 | 黄色网址免费大全 | 亚洲国产情侣偷自在线二页 |