โมดูลNode.js HTTPS
ตัวอย่าง
สร้างเซิร์ฟเวอร์ https ที่รับฟังพอร์ต 8080 ของคอมพิวเตอร์ของคุณ
เมื่อเข้าถึงพอร์ต 8080 ให้เขียนว่า "สวัสดีชาวโลก!" กลับมาเป็นคำตอบ:
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 มีวิธีทำให้ Node.js ถ่ายโอนข้อมูลผ่านโปรโตคอล HTTP TLS/SSL ซึ่งเป็นโปรโตคอล HTTP ที่ปลอดภัย
ไวยากรณ์
ไวยากรณ์สำหรับการรวมโมดูล HTTPS ในแอปพลิเคชันของคุณ:
var https = require('https');
คุณสมบัติและวิธีการ 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 |