我正在使用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 btw)
谢谢!
代码:
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");发布于 2021-01-10 09:20:27
Polipo不终止HTTPS: HTTPS上的请求必须使用CONNECT请求通过代理进行隧道传输,而不是使用GET请求发送到代理。
https://stackoverflow.com/questions/20750220
复制相似问题