Node.js+;Polipo https请求错误

Node.js+;Polipo https请求错误,node.js,tor,polipo,Node.js,Tor,Polipo,我正在用polipo和tor做一个简单的例子,它在我的firefox浏览器上运行良好。我已将polipo设置为代理,浏览器工作正常 然后,我尝试在node.js中根据一个简单的示例执行一个简单的请求,但没有成功。 如果我尝试执行请求,则效果很好。但如果我请求https://,则会发生以下错误: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd

我正在用polipo和tor做一个简单的例子,它在我的firefox浏览器上运行良好。我已将polipo设置为代理,浏览器工作正常

然后,我尝试在node.js中根据一个简单的示例执行一个简单的请求,但没有成功。 如果我尝试执行请求,则效果很好。但如果我请求https://,则会发生以下错误:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN""http://www.w3.org/TR/html4/loose.dtd">
<html><head>
<title>Proxy error: 400 Couldn't parse URL.</title>
</head><body>
<h1>400 Couldn't parse URL</h1>
<p>The following error occurred while trying to access <strong>https://check.torproject.org</strong>:<br><br>
<strong>400 Couldn't parse URL</strong></p>
<hr>Generated Mon, 23 Dec 2013 17:22:04 BRST by Polipo on <em>localhost:8118</em>.
</body></html>
奇怪的是,这个页面在firefox上运行良好。我想知道这段代码是否有问题,或者我只是无法使用polipo执行HTTPS请求

有没有人有我可以测试的解决方案或东西?(顺便说一句,我正在使用mac)

谢谢大家!

守则:

var request = function(name, url, proxy) {
// options
var options = URL.parse(url, false);
// headers
options.headers = {
    accept: '*/*',
    'content-length': 0
};
var body = '';
// proxy set
if(proxy) {
    var proxy = URL.parse(proxy, false);
    options.path = options.protocol+ '//'+ options.host+ options.path;
    options.headers.host = options.path;
    options.protocol = proxy.protocol;
    options.host = proxy.host;
    options.port = proxy.port;
    options.hostname = proxy.hostname;
}
console.log(name, 'request options:', options);

var r = (options.protocol == 'http:'?http:https).request(options, function(res) {
    res.on('end', function() {
        // just print ip, instead of whole body
        //console.log(name, body.match(/check_ip" value="([^"]*)"/)[1]);
        console.log(body);
        // console.log(name, body);
    });
    res.on('readable', function() {
        body += this.read().toString();
    });
});
r.end();
};

request('with proxy', 'https://check.torproject.org/', "http://localhost:8118");

Polipo不终止HTTPS:HTTPS上的请求必须使用CONNECT请求通过代理进行隧道传输,而不是使用GET请求发送到代理

var request = function(name, url, proxy) {
// options
var options = URL.parse(url, false);
// headers
options.headers = {
    accept: '*/*',
    'content-length': 0
};
var body = '';
// proxy set
if(proxy) {
    var proxy = URL.parse(proxy, false);
    options.path = options.protocol+ '//'+ options.host+ options.path;
    options.headers.host = options.path;
    options.protocol = proxy.protocol;
    options.host = proxy.host;
    options.port = proxy.port;
    options.hostname = proxy.hostname;
}
console.log(name, 'request options:', options);

var r = (options.protocol == 'http:'?http:https).request(options, function(res) {
    res.on('end', function() {
        // just print ip, instead of whole body
        //console.log(name, body.match(/check_ip" value="([^"]*)"/)[1]);
        console.log(body);
        // console.log(name, body);
    });
    res.on('readable', function() {
        body += this.read().toString();
    });
});
r.end();
};

request('with proxy', 'https://check.torproject.org/', "http://localhost:8118");