не удалось установить сокет туннелирования ошибки запроса HTTP PROXY для узла js statuscode = 403 - PullRequest
0 голосов
/ 11 марта 2019

У меня есть приложение узла. Я пытаюсь подключиться к XML API через прокси. Мне нужен прокси, потому что я размещаю свое приложение на Heroku, и IP-адреса все время меняются из-за выравнивания нагрузки на сервере Amazon AWS. Прокси должен быть разблокирован ИТ-фирмой, чтобы иметь доступ к 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

Требования:

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,

Если вам нужна дополнительная информация, я с удовольствием отредактирую.

Спасибо за ваши усилия.

...