1

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

然后我尝试根据一个简单的例子在node.js中做一个简单的请求,但没有成功。如果我尝试向http://check.torproject.org发出请求,它工作正常。但是如果我向 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>

我发送的标题:

options: { protocol: 'http:',
slashes: true,
auth: null,
host: 'localhost:8118',
port: '8118',
hostname: 'localhost',
hash: null,
search: null,
query: null,
pathname: '/',
path: 'https://check.torproject.org',
href: 'https://check.torproject.org',
headers: 
{ accept: '*/*',
 'content-length': 0,
 host: 'https://check.torproject.org' } 
}

奇怪的是,这个页面在 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");
4

1 回答 1

0

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

于 2021-01-10T01:20:27.403 回答