简体   繁体   English

HTTPS 通信使用 NodeJS TLS 套接字

[英]HTTPS communication using NodeJS TLS socket

I want to communicate with a web server from NodeJS.我想从 NodeJS 与 web 服务器通信。 This is what I tried:这是我尝试过的:

let tls = require("tls");
(async function() {
    let socket = tls.connect(443, "google.com", {servername: "google.com"});
    socket.on("OCSPResponse", function(response) {
        console.log(response);
    });
    socket.write(`GET / HTTP/1.1\r\nHost: google.com`);
})();

There's no output.没有 output。 I'm expecting to use a similar technique with HTTP servers too using net module我也希望使用net模块对 HTTP 服务器使用类似的技术

let tls = require("tls");
(async function() {
    let socket = tls.connect(443, "google.com", {servername: "google.com"});
    socket.on("data", function(response) {
        console.log(response);
    });
    socket.setEncoding("utf8");
    socket.write(`GET / HTTP/1.1\nHost: www.google.com\n\n`);
})();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM