node js HttpProxyAgent连接ENOENT

时间:2015-12-24 17:04:01

标签: javascript node.js

我正在尝试连接到服务器并使用代理发送一些http请求,但我在设置客户端时遇到问题。很难解释所以我只会发布我所拥有的内容。

var url = require('url');
var http = require('http');
var HttpProxyAgent = require('http-proxy-agent');

var proxylist = [
    "1.234.45.50"
];

//pick a random array
function randomarray(array) {
    return array[Math.floor(Math.random() * array.length)];
}

//Agent 
function getagent() {
    // HTTP/HTTPS proxy to connect to 
    var proxy = process.env.http_proxy || randomarray(proxylist);
    console.log('using proxy: ' + proxy);

    var agent = new HttpProxyAgent(proxy);
    console.log(agent);
    return agent
}

输出是:

using proxy: 1.234.45.50
HttpProxyAgent {
  domain: null,
  _events: {},
  _eventsCount: 0,
  _maxListeners: undefined,
  callback: [Function: connect],
  secureProxy: false,
  proxy:
   { protocol: null,
     slashes: null,
     auth: null,
     host: null,
     port: 80,
     hostname: null,
     hash: null,
     search: null,
     query: null,
     pathname: '1.234.45.50',
     path: '1.234.45.50',
     href: '1.234.45.50',
     parse: [Function],
     format: [Function],
     resolve: [Function],
     resolveObject: [Function],
     parseHost: [Function] } }
Failed to request server (error=REQUEST_ERROR, error_source=Error: connect ENOENT 1.234.45.50)

0 个答案:

没有答案