Proxy http到https节点代理

Proxy http到https节点代理,proxy,http-proxy,node-http-proxy,Proxy,Http Proxy,Node Http Proxy,我想知道设置代理的最简单方法,在那里我可以在(即,localhost:8011中发出HTTP请求,代理在localhost:443中发出HTTPS请求(来自服务器的HTTPS应答也应该由代理转换为HTTP) 我正在使用node.js 我尝试过http代理,如下所示: var httpProxy = require('http-proxy'); var options = { changeOrigin: true, target: { https: true } } ht

我想知道设置代理的最简单方法,在那里我可以在(即,
localhost:8011
中发出HTTP请求,代理在
localhost:443
中发出HTTPS请求(来自服务器的HTTPS应答也应该由代理转换为HTTP)

我正在使用node.js

我尝试过http代理,如下所示:

var httpProxy = require('http-proxy');
var options = {
  changeOrigin: true,
  target: {
      https: true
  }
}

httpProxy.createServer(443, 'localhost', options).listen(8011);
我也试过:

httpProxy.createProxyServer({   
    target: {
        host:'https://development.beigebracht.com',
        rejectUnauthorized: false,
        https: true,   
    } 
}).listen(port);
但是当我尝试连接时,我得到了这个错误

/Users/adrian/Development/beigebracht-v2/app/webroot/node_modules/http-proxy/lib/http-proxy/passes/web-incoming.js:103
    var proxyReq = (options.target.protocol === 'https:' ? https : http).reque
                                  ^
TypeError: Cannot read property 'protocol' of undefined
我想用node来做,但是,其他解决方案也可以有效。
(该代理仅用于本地主机的测试目的,因此安全性不是问题)

我需要一个HTTP->HTTPS节点代理进行单元测试。我最后做的是创建HTTP代理,然后让它侦听并处理
connect
事件。当服务器接收到连接请求时,它会设置一个到HTTPS目标URL的隧道,并将所有数据包从客户端套接字转发到目标套接字,反之亦然

示例代码:

var httpProxy = require('http-proxy');
var net = require('net');
var url = require('url');

var options = {
    host: 'localhost',
    port: 3002
};

var proxy = httpProxy.createProxyServer();

proxy.http = http.createServer(function(req, res) {

    var target = url.parse(req.url);

    // The `path` attribute would cause problems later.
    target.path = undefined;

    proxy.web(req, res, {
        target: target
    });

}).listen(options.port, options.host);

// This allows the HTTP proxy server to handle CONNECT requests.
proxy.http.on('connect', function connectTunnel(req, cltSocket, head) {

    // Bind local address of proxy server.
    var srvSocket = new net.Socket({
        handle: net._createServerHandle(options.host)
    });

    // Connect to an origin server.
    var srvUrl = url.parse('http://' + req.url);

    srvSocket.connect(srvUrl.port, srvUrl.hostname, function() {
        cltSocket.write(
            'HTTP/1.1 200 Connection Established\r\n' +
            'Proxy-agent: Node.js-Proxy\r\n' +
            '\r\n'
        );
        srvSocket.write(head);
        srvSocket.pipe(cltSocket);
        cltSocket.pipe(srvSocket);
    });
});

目前我自己也在这个过程中。你确定目标是一个对象吗?看起来应该是url字符串?