Node.js HTTPS 模組
示例
建立監聽您計算機 8080 埠的 https 伺服器。
當訪問 8080 埠時,請以“Hello World!”作為響應寫回
var https = require('https');
https.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(8080);
執行示例 »
定義和用法
HTTPS 模組提供了一種透過 HTTP TLS/SSL 協議(即安全 HTTP 協議)傳輸資料的方式。
語法
在應用程式中包含 HTTPS 模組的語法
var https = require('https');
HTTPS 屬性和方法
方法 | 描述 |
---|---|
createServer() | 建立一個 HTTPS 伺服器 |
get() | 將方法設定為 GET,並返回一個包含使用者請求的物件 |
globalAgent | 返回 HTTPS Agent |
request | 向安全 Web 伺服器發出請求 |