NodeJS http 和 https 模块有什么区别?

What is difference between NodeJS http and https module?

我在我的项目中使用了 http 模块,但我的大部分 'post' 请求都被邮递员阻止了。 我读到这是一个 ssl 问题,经过一些研究我发现了另一个名为 https 的模块。

这是我当前的代码。

 var http = require('http');

var server = http.createServer(app);

嘿,确保 Postman 中的拦截器已关闭(它应该在顶部,"Sign in" 按钮的左侧)

与 https 相关,如 Node.js v5.10.1 文档中所述

HTTPS is the HTTP protocol over TLS/SSL. In Node.js this is implemented as a separate module.

我曾经用它通过 https(端口 443)从我的服务器向其他服务器发出请求。

顺便说一句,您的代码应该不起作用,试试这个

const http = require('http');
http.createServer( (request, response) => {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World\n');
}).listen(8124);
console.log('Server running at http://127.0.0.1:8124/');

并在 Postman 中使用 http://127.0.0.1:8124 ..希望它有所帮助

HTTPHTTPS 的区别在于,如果您需要通过 SSL 与服务器通信,使用证书加密通信,您应该使用 HTTPS ,否则你应该使用 HTTP,例如:

使用 HTTPS 你可以做类似的事情:

var https = require('https');

var options = {
    key : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.key')).toString(),
    cert : fs.readFileSync(path.resolve(__dirname, '..', 'ssl', 'prd', 'cert.crt')).toString(),
};

var server = https.createServer(options, app);
server = server.listen(443, function() {
    console.log("Listening " + server.address().port);
});
const http = require('http');
http.createServer( function(request, response) {
   response.writeHead(200, {'Content-Type': 'text/plain'});
   response.end('Hello World\n');
}).listen(3000);
console.log('Server running at http://localhost:3000/');