Monday 15 June 2015

javascript - How to connect to a proxy server and make an http.request via the proxy using nodejs? -



javascript - How to connect to a proxy server and make an http.request via the proxy using nodejs? -

i'm not trying create server proxy want connect proxy , send http requests via that.

example:

proxy.connect(someip:someport,function(){ console.log('[pm]['+this._account+'] logging in..'); var auth_re = /auth\.chatango\.com ?= ?([^;]*)/; var info = querystring.stringify({user_id: this._account, password: this._password, storecookie: 'on', checkerrors: 'yes'}); var options = {hostname: 'chatango.com', port: 80, path: '/login', method: 'post', headers: {'connection': 'keep-alive', 'content-length': data.length, 'cache-control': 'max-age=0', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'origin': 'http://chatango.com', 'user-agent': 'mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/38.0.2125.104 safari/537.36', 'content-type': 'application/x-www-form-urlencoded', 'referer': 'http://chatango.com/login', 'accept-encoding': 'gzip,deflate', 'accept-language': 'en-us,en;q=0.8'}}; var self = this; var req = http.request(options, function(res) { res.setencoding('utf8'); if (res.headers['set-cookie'][2]) { var m = auth_re.exec(res.headers['set-cookie'][2]); if (m) homecoming callback(m[1]); } callback(false); }).on('error', function(e) { callback(false); }); req.write(data); req.end(); });

i dont know if i'm tired of seeing answers creating proxy want connect 1 not create one

http proxy because login page uses http request

and found reply

console.log('[pm]['+this._account+'] logging in..'); var auth_re = /auth\.chatango\.com ?= ?([^;]*)/; var info = querystring.stringify({user_id: this._account, password: this._password, storecookie: 'on', checkerrors: 'yes'}); var options = {hostname: 'chatango.com', port: 80, path: '/login', method: 'post', headers: {'connection': 'keep-alive', 'content-length': data.length, 'cache-control': 'max-age=0', 'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'origin': 'http://chatango.com', 'user-agent': 'mozilla/5.0 (windows nt 6.3; wow64) applewebkit/537.36 (khtml, gecko) chrome/38.0.2125.104 safari/537.36', 'content-type': 'application/x-www-form-urlencoded', 'referer': 'http://chatango.com/login', 'accept-encoding': 'gzip,deflate', 'accept-language': 'en-us,en;q=0.8'}}; var self = this; if(self.proxy.url && self.proxy.port){ globaltunnel.initialize({ host: self.proxy.url, port: self.proxy.port, tunnel: 'neither', protocol: 'http' }); } var req = http.request(options, function(res) { res.setencoding('utf8'); if (res.headers['set-cookie'][2]) { var m = auth_re.exec(res.headers['set-cookie'][2]); if (m) homecoming callback(m[1]); } callback(false); }).on('error', function(e) { console.log(e); callback(false); }); req.write(data); req.end(); if(self.proxy.url && self.proxy.port){ globaltunnel.end(); }

javascript node.js proxy

No comments:

Post a Comment