如何使用nodejs连接到代理服务器并通过代理进行http.request
How to connect to a proxy server and make an http.request via the proxy using nodejs?
我不想让我的服务器代理做任何我想连接到代理并通过它发送http请求的事情。
示例:
proxy.connect(someip:someport,function(){
console.log('[PM]['+this._account+'] Logging in..');
var auth_re = /auth'.chatango'.com ?= ?([^;]*)/;
var data = 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, like 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) return callback(m[1]);
}
callback(false);
}).on('error', function(e) {
callback(false);
});
req.write(data);
req.end();
});
我不知道它是否会看起来像那样,但我厌倦了看到创建代理的答案我只想连接到一个而不是创建一个
http代理,因为登录页面使用http请求
我找到了我的答案
console.log('[PM]['+this._account+'] Logging in..');
var auth_re = /auth'.chatango'.com ?= ?([^;]*)/;
var data = 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, like 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) return 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();
}
相关文章:
- 在不打开聊天屏幕的情况下制作Zopim-ding代理
- Ajax调用ERror Cross Origin REquest:在rails中自动完成大学列表
- https.request ignoring rejectUnauthorized
- Javascript ajax request
- servlet和代理servlet之间的区别
- node js post request.body undefined
- 带有Request.Form的JScript数组
- 向localhost发出带有grunt的代理CORS请求
- PHP代理jQuery部分为javascript
- 代理一个网站能够在iframe中进行所见即所得编辑-它是如何工作的
- 在Chrome for iOS中,附加到用户代理字符串的唯一选项卡ID
- jQuery的等价物's$(this)在Ractive.js事件代理中
- 在http服务单元测试中使用request-js时,chai.request不是一个函数
- 正在发送请求中包含数组的qx.io.request.Xhr请求
- WebRTC-是否可以将浏览器代理视频从源发送到接收器
- 使用nock模拟mocha中具有特定请求头的超级代理请求
- Apache2反向代理重定向
- Angular Cross Origin Request CORS失败,但节点http.get()成功返回
- 如何使用nodejs连接到代理服务器并通过代理进行http.request
- Node / Express / Request -尝试用参数代理POST请求抛出“结束后写入”