Modulo HTTPS Node.js
Esempio
Crea un server https in ascolto sulla porta 8080 del tuo computer.
Quando si accede alla porta 8080, scrivi "Hello World!" indietro come risposta:
var https = require('https');
https.createServer(function (req, res)
{
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen(8080);
Definizione e utilizzo
Il modulo HTTPS fornisce un modo per fare in modo che Node.js trasferisca i dati sul protocollo HTTP TLS/SSL, che è il protocollo HTTP sicuro.
Sintassi
La sintassi per includere il modulo HTTPS nell'applicazione:
var https = require('https');
Proprietà e metodi 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 |