0
は、私がアクセスしています任意のページからhttp requests
を返す必要があり、プロキシサーバーをセットアップしようとしています。Node.jsのHTTPプロキシトラフィック監視
私はwww.google.com
に移動した場合、基本的に、私は次の要求を取得するために期待している:
はnode-http-proxy
モジュールを使用して、この達成可能ですか?
...
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
}).listen(8000);
http.createServer(function (req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
UPDATE:私は私のプロキシサーバーを使用するには、ブラウザを設定して、コードを変更し
var http = require('http'),
httpProxy = require('http-proxy');
//
// Create a proxy server with custom application logic
//
var proxy = httpProxy.createServer(function (req, res, proxy) {
//
// Put your custom server logic here
//
proxy.proxyRequest(req, res, {
host: 'localhost',
port: 9000
});
})
proxy.listen(8000);
proxy.on('proxyReq', function(proxyReq, req, res, options) {
console.log(req.url);
console.log(proxyReq.url);
});
http.createServer(function(req, res) {
res.writeHead(200, { 'Content-Type': 'text/plain' });
res.write('request successfully proxied: ' + req.url +'\n' + JSON.stringify(req.headers, true, 2));
res.end();
}).listen(9000);
をしかし、私は別のウェブサイト
これは動作しますが、どのように私は、HTTPリクエストのURLを取得できますか?私は 'はconsole.log(req.url)を行う場合は'それはログに記録します。 'http://detectportal.firefox.com/success.txt http://google.com/ ます。http://detectportal.firefox。 com/success.txt http://detectportal.firefox.com/success.txt http://detectportal.firefox.com/success.txt など – Valip
取得予定: http: // google.com/'、'?gws_rd = cr&ei = ed4SWeCbNIKYsAHxmIvACw'、 'googlelogo_color_120x44dp.png'など – Valip
[リクエストの書き換えに関するドキュメント](https://github.com/nodejitsu/node)を参照する必要があると思います-http-proxy#setup-a-stand-alone-proxy-server-with-proxy-request-header-re-writing)を使用します。ここで元のリクエストにアクセスする必要があります –