【问题标题】:HTTPS communication using NodeJS TLS socket使用 NodeJS TLS 套接字的 HTTPS 通信
【发布时间】:2020-07-17 22:05:15
【问题描述】:

我想通过 NodeJS 与 Web 服务器通信。这是我尝试过的:

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`);
})();

没有输出。我也希望使用net 模块对 HTTP 服务器使用类似的技术

【问题讨论】:

    标签: javascript node.js sockets http https


    【解决方案1】:
    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`);
    })();
    

    【讨论】:

      猜你喜欢
      • 2019-02-14
      • 1970-01-01
      • 1970-01-01
      • 2016-06-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多