Mô-đun HTTPS Node.js

❮ Mô-đun tích hợp


Thí dụ

Tạo một máy chủ https lắng nghe trên cổng 8080 của máy tính của bạn.

Khi cổng 8080 được truy cập, hãy viết "Hello World!" trở lại như một phản hồi:

var https = require('https');

https.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.write('Hello World!');
  res.end();
}).listen(8080);

Định nghĩa và Cách sử dụng

Mô-đun HTTPS cung cấp một cách để Node.js truyền dữ liệu qua giao thức HTTP TLS / SSL, là giao thức HTTP an toàn.


Cú pháp

Cú pháp để bao gồm mô-đun HTTPS trong ứng dụng của bạn:

var https = require('https');

Thuộc tính và phương pháp HTTPS

Method Description
createServer() Creates an HTTPS server
get() Sets the method to GET, and returns an object containing the user's request
globalAgent Returns the HTTPS Agent
request Makes a request to a secure web server

❮ Mô-đun tích hợp