2017-07-21 126 views
0

我觉得很难用superagent-proxy,只需用简单的代码:如何使用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); 
    }) 

,但在运行时,就不能得到一个答复,为什么呢?

+0

是否有错误代码 – Qiu

+0

没有错误,也没有回复.. – hanzichi

回答

0

你应该:?

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 } 
+0

行为,而不是那种方式,我什么都没有 – hanzichi