[英]NodeJS writing a socket through a proxy
我正在嘗試通過我擁有的代理進行TCP客戶端連接:
IP:12.32.492.94
端口:8081
用戶名:acct
通過:admin123
不太清楚該怎么做。 有任何想法嗎?
var client = new net.Socket();
client.connect(port, ip, function() {
});
client.on('connect', function() {
console.log('connected');
});
client.on('data', function(data) {
console.log(data);
});
需要使用socks npm模塊來做我想做的事情。 需要一個襪子代理。
“襪子”:“ 1.1.8”
var Socks = require('socks');
var options = {
proxy: {
ipaddress: "202.101.228.108", // Random public proxy
port: 1080,
type: 5 // type is REQUIRED. Valid types: [4, 5] (note 4 also works for 4a)
},
target: {
host: "google.com", // can be an ip address or domain (4a and 5 only)
port: 80
},
command: 'connect' // This defaults to connect, so it's optional if you're not using BIND or Associate.
};
Socks.createConnection(options, function(err, socket, info) {
if (err)
console.log(err);
else {
// Connection has been established, we can start sending data now:
socket.write("GET / HTTP/1.1\nHost: google.com\n\n");
socket.on('data', function(data) {
console.log(data.length);
console.log(data);
});
// PLEASE NOTE: sockets need to be resumed before any data will come in or out as they are paused right before this callback is fired.
socket.resume();
// 569
// <Buffer 48 54 54 50 2f 31 2e 31 20 33 30 31 20 4d 6f 76 65 64 20 50 65...
}
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.