为什么我无法使用SOCKS5连接用户名和密码,如
用户名:密码@ip:端口,我可以使用HTTP,但不能使用SOCKS5
doneusername:password @ ip:port,我可以使用HTTP,但不能使用SOCKS5
完成
SOCKS5;用户名:密码@ IP:端口
var service = {
create: create,
businesses: [],
upVote: upVote,
showAllBiz: showAllBiz,
};
function showAllBiz(){
$http.get("/api/businesses")
.then(function(res) {
service.businesses = res.data;
}, function(err) {
$log.info(err);
});
}
function create(data) {
return $http({
method: 'POST',
url: '/api/businesses',
data: data,
headers: {
'Content-Type': 'application/json'
}
}).then(function(res) {
service.businesses.push(res.data);
});
}
答案 0 :(得分:0)
通过所有讨论,我得到了您的createAgent的问题。
所以使用此代码并感到高兴(:
function createAgent(connectionString, type) {
var type = parseInt(type || 5);
var ipParts = connectionString.split('@'); // splitting user:pass@host:port
var host, port, username, password;
switch(ipParts.length) {
case 3 : // somebody@somewhere.com:somepassword@proxy.com:1080
var credentials = (ipParts[0]+'@'+ipParts[1]).split(':'); // yusolokuji@leeching.net:luquitas
username = credentials[0]; // somebody@somewhere.com
password = credentials[1]; // somepassword
var hostParts = ipParts[2].split(':'); // proxy.com:1080
host = hostParts[0];
port = hostParts[1] || 1080;
break;
case 2 : // somebody:somepassword@proxy.com:1080
var credentials = ipParts[0].split(':'); // somebody:somepassword
username = credentials[0]; // somebody
password = credentials[1]; // somepassword
var hostParts = ipParts[1].split(':'); // proxy.com:1080
host = hostParts[0];
port = hostParts[1] || 1080;
break;
case 1 : // proxy.com:1080
ipParts = ipParts[0].split(':');
host = ipParts[0];
port = ipParts[1];
break;
}
var config = {
proxy: {
ipaddress: host,
port: parseInt(port),
type: type
}
};
if(type == 5) {
config.proxy.authentication = {
username: username,
password: password
};
}
if(type == 4) {
config.proxy.user_id = username;
}
return new Socks.Agent(config);
}