我发现很难使用superagent-proxy,只需要简单的代码:
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);
})但是当它运行的时候,却得不到响应,为什么?
发布于 2017-07-21 17:53:11
您应该:
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 }发布于 2021-11-12 08:24:09
你的代码是正确的,代理网址是不正确的-如果它的确切的'http://221.237.122.22:8118‘它意味着代理不需要任何登录,任何人都可以使用它只需要网址,这不是大多数代理的情况,通常代理网址类似于'http://username:password@IPADDRESS_OR_HOST:PORT’
https://stackoverflow.com/questions/45233845
复制相似问题