P
P
porcospinocarryon2021-08-14 09:21:19
Node.js
porcospinocarryon, 2021-08-14 09:21:19

How to send a request through a proxy?

I have a proxy address that looks something like this: 185.233.80.131 : 9122 : GVF7nV : kbh32Z (ip address : port : login : password). To send a request through a proxy, I use Tunnel .

const tunnelingAgent = tunnel.httpOverHttps({
  proxy: getProxyOptions(),
});

const req = https.request(
  {
    host: 'url сайта, к которому хочу обратиться через proxy',
    port: 443,
    agent: tunnelingAgent,
  },
  (res) => {
    console.log(res);
  }
);

function getProxyOptions() {
  return {
    host: '185.233.80.131',
    port: 9122,
    proxyAuth: 'GVF7nV:kbh32Z'
  };
}


But an error occurs: Error: tunneling socket could not be established, cause=write EPROTO 12248:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c :332

Judging by the answers on the Internet, such an error indicates the use of https in the address, while when accessing the proxy, you need to use http.

But when I try to write something like this:
function getProxyOptions() {
  return {
    host: 'http://185.233.80.131',
    port: 9122,
    proxyAuth: 'GVF7nV:kbh32Z'
  };
}

Gives an error:
Error: tunneling socket could not be established, cause=getaddrinfo ENOTFOUND 185.233.80.131 Can

you please tell me how to solve this problem?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question