【问题标题】:nodejs make a GET call to an https sitenodejs 对 https 站点进行 GET 调用
【发布时间】:2014-07-02 20:52:31
【问题描述】:

我在 ubuntu 12LTS 上使用 nodejs v0.10.28, 我正在尝试使用此测试代码向 Web 代理后面的 https 启用站点发出请求:

 var http = require("http");

    var options = {
        host: "mycompany.proxy.host",
        port: 8088,
        //host: "https://login.launchpad.net",
        //port: 443,
        //path: "/",
        headers: {
           Host: "login.launchpad.net"
        }
     };
     http.get(options, function(res) {
        console.log(res);
        res.pipe(process.stdout);
     }).on('error', function(e) {
        console.log(e);
     });

但不确定用于成功进行 HTTP GET 的正确选项参数是什么

【问题讨论】:

  • 你得到了什么错误?
  • 您可能会发现请求更容易使用 - github.com/mikeal/request - 它是 Node 的 HTTP/HTTPS 功能的包装器,并且它支持代理。
  • ..谢谢这个关于请求的提示让我更接近答案..

标签: node.js http https proxy


【解决方案1】:

您应该使用节点 https 而不是 http 模块来发出 https 请求。否则服务器很可能会重置您的连接,并且错误处理程序将捕获 ECONNRESET 错误。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-06-29
    • 2016-04-15
    • 1970-01-01
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    相关资源
    最近更新 更多