节点js HTTP PROXY请求错误无法建立隧道套接字statuscode = 403

时间:2019-03-11 09:47:58

标签: javascript node.js http-proxy

我有一个节点应用程序。我尝试通过代理连接到XML API。我需要一个代理,因为我将应用程序托管在Heroku上,并且由于Amazon AWS服务器上发生负载平衡,因此IP地址一直在变化。 IT公司需要解锁代理才能访问XML API。他们保证IP输入已经完成,并且IP已解锁。

以下代码段创建了请求:

   async send(method, url, options){
        const reqOptions = {
            headers: {},
            ...options,
            url,
            method,
        };
        //use system proxy
        if( Environment.HTTP_PROXY ){
            reqOptions.proxy = this.proxyUrl;
        }
        if( method === 'POST' || method === 'PUT' ){
            reqOptions.body = options.data;
            if( !reqOptions.headers['Content-Type'] ){
                reqOptions.headers['Content-Type'] = 'application/xml';
            }
        }

        return new Promise( (resolve, reject) => {
            const req = request(reqOptions, function(error, response, body) {
                if( error ){
                    console.log("Got error: " + error);
                    reject();
                }else{
                    resolve(body);
                }
             });
             if( this.username && this.password ){
                req.auth(this.username, this.password);
             }
        });
    }

我收到以下错误:

  

错误:无法建立隧道套接字,statusCode = 403

reqOptions:

proxy:
   Url {
     protocol: 'http:',
     slashes: true,
     auth: null,
     host: '--.---.--.---:--',
     port: '--',
     hostname: '--.---.--.---',
     hash: null,
     search: null,
     query: null,
     pathname: '/',
     path: '/',
     href: 'http://--.---.--.---:--/' },
  tunnel: true,
agent:
   TunnelingAgent {
 options:
  { proxy: [Object],
    headers: [Object],
    ca: undefined,
    cert: undefined,
    key: undefined,
    passphrase: undefined,
    pfx: undefined,
    ciphers: undefined,
    rejectUnauthorized: undefined,
    secureOptions: undefined,
    secureProtocol: undefined },
 proxyOptions:
  { host: '--.---.--.---',
    port: --,
    proxyAuth: null,
    headers: [Object] },
 maxSockets: Infinity,
 requests: [],
 sockets: [ {} ],
 _events: [Object: null prototype] { free: [Function: onFree] },
 _eventsCount: 1,
 request: [Function: request],
 createSocket: [Function: createSecureSocket],
 defaultPort: --- },
  setHost: true,
  originalCookieHeader: undefined,
  _disableCookies: true,
  _jar: undefined,
  port: '----',
  host: '--.---.---.---',
  path:
   '/v8/fidelioiiswrapper.dll/fidelioxmlinterface.datahandler?ic=XX',
  httpModule:
   { Agent: [Function: Agent],
 globalAgent:
  Agent {
    _events: [Object],
    _eventsCount: 1,
    _maxListeners: undefined,
    defaultPort: 443,
    protocol: 'https:',
    options: [Object],
    requests: {},
    sockets: {},
    freeSockets: {},
    keepAliveMsecs: 1000,
    keepAlive: false,
    maxSockets: Infinity,
    maxFreeSockets: 256,
    maxCachedSessions: 100,
    _sessionCache: [Object] },
 Server: [Function: Server],
 createServer: [Function: createServer],
 get: [Function],
 request: [Function] },
  _started: true,
 

如果您需要更多信息来帮助我,我们很乐意进行编辑。

感谢您的努力。

0 个答案:

没有答案