首页 > 解决方案 > 在下面的代码中使用 Express GET 方法和 HTTPS GET 方法有什么区别?

问题描述

const express = require("express");
const app = express();
const https = require("https");

app.get("/", function (req, res){
  var url = "https://***";
  https.get(url, function(response){
    console.log(response);
  });
  res.send("server running");
});

标签: node.jsexpresshttpsgetweb-development-server

解决方案


app.get()为本地 Express 服务器上的特定 INCOMING http 请求路径注册一个侦听器。

https.get()向其他 https 服务器发出 OUTBOUND https 请求以从该其他服务器获取内容。

而且,显然,https.get()使用的是 https,而不是 http。app.get()可能正在监听任何一个 - 这取决于它所属的服务器是如何启动的(作为 http 服务器或 https 服务器),您在问题中的代码没有显示。


推荐阅读