1

私は tor で polipo を使用して簡単な例を実行していますが、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 リクエストを実行できないのでしょうか。

誰かが私がテストできる解決策や何かを持っていますか? (ちなみにマックを使っています)

ありがとうございました!

コード:

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