如何使用超级代理代理?



我发现很难使用超级代理代理,只需使用简单的代码:

const superagent = require('superagent')
require('superagent-proxy')(superagent)
let proxy = 'http://221.237.122.22:8118' // 设置代理
superagent
.get('http://sf.gg')
.proxy(proxy)
.timeout(3600*1000)
.end((err, res) => {
console.log(res)
console.log(res.status, res.headers);
console.log(res.body);
})

但是在运行时,它无法得到回复,为什么?

你应该:

const superagent = require('superagent')
require('superagent-proxy')(superagent)
let proxy = 'http://221.237.122.22:8118' // 设置代理
superagent
.get('http://sf.gg')
.proxy(proxy)
.timeout(3600*1000)
.end((err, res) => {
if(err) {
console.error(err);
return;
}
console.log(res)
console.log(res.status, res.headers);
console.log(res.body);
})

然后,您将收到错误,例如

{ Error: connect ECONNREFUSED 221.237.122.22:8118
at Object.exports._errnoException (util.js:1018:11)
at exports._exceptionWithHostPort (util.js:1041:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1086:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '221.237.122.22',
port: 8118,
response: undefined }

您的代码是正确的,代理 URL 不是 - 如果它完全正确 "http://221.237.122.22:8118" 这意味着代理不需要任何登录,任何人都可以仅使用URL使用它,大多数代理都不是这种情况,通常代理URL就像"http://username:password@IPADDRESS_OR_HOST:PORT">

最新更新