Mô-đun HTTPS của Node.js
Ví dụ
Tạo máy chủ https lắng nghe trên cổng 8080 trên máy tính của bạn.
Khi cổng 8080 được truy cập, hãy viết "Xin chào thế giới!" trở lại như một phản ứng:
var https = require('https');
https.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(8080);
Chạy ví dụ »Định nghĩa và cách sử dụng
Mô-đun HTTPS cung cấp cách tạo dữ liệu truyền Node.js qua giao thức HTTP TLS/SSL, đây là giao thức HTTP an toàn.
Cú pháp
Cú pháp để đưa mô-đun HTTPS vào ứng dụng của bạn:
var https = require('https');
Thuộc tính và phương thức 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 |