首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Node.js + Polipo https请求错误

Node.js + Polipo https请求错误
EN

Stack Overflow用户
提问于 2013-12-24 03:49:26
回答 1查看 537关注 0票数 1

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

然后我试着根据一个简单的例子用node.js做一个简单的请求,它不起作用。如果我尝试向http://check.torproject.org发出请求,它工作得很好。但是,如果我向https://,发出请求,则会出现以下错误:

代码语言:javascript
复制
<!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>

我发送的报头:

代码语言:javascript
复制
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)

谢谢!

代码:

代码语言:javascript
复制
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");
EN

回答 1

Stack Overflow用户

发布于 2021-01-10 09:20:27

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20750220

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档