1

I am trying to make a request to a 3rd party SOAP API, provided an IP address http://XXX.XXX.XXX.XXX:40871

I get the following error:

{
    "success": false,
    "error": "connect ECONNREFUSED XXX.XXX.XXX.XXX:40871",
    "trace": "Error: connect ECONNREFUSED XXX.XXX.XXX.XXX:40871\n    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1187:16)"
}

while testing locally I edited my hosts file and provided a host name to the IP

XXX.XXX.XXX.XXX my-host-name.com

then made a request to http://my-host-name.com:40871 and successfully got a response.

I can not do this in production since we are using heroku to deploy our app.

Our app is a middleware to make requests to the 3rd party API since they requires a static IP in its whitelist. we create a axios instance and recieve further options in the request body.

const agent = new HttpsProxyAgent(process.env.STATIC_URL!);
const baseOptions: AxiosRequestConfig = {
    proxy: false,
    httpsAgent: agent,
};
const instance = axios.create(baseOptions);
const response = await instance(req.body);

res.send({ success: true, response: response.data });

here is the request body:

{
    "method": "POST",
    "baseURL": "http://XXX.XXX.XXX.XXX:40871",
    "url": "/IDORequestService/IDOWebService.asmx",
    "data": {{xmlBody}},
    "headers": {
      "Content-type": "text/xml",
      "SOAPAction": "http://frontstep.com/IDOWebService/CreateSessionToken",
      "Accept": "*/*",
      "Accept-Encoding": "gzip, deflate, br",
      "Connection": "keep-alive"
  }
}

Expected behavior: it should work with IP addresses

Environment:

  • Axios v0.27.2
  • https-proxy-agent: v5.0.1
  • Node.js v16.16.0
  • OS: Windows 11/Linux Mint 19.3
O. Jones
  • 103,626
  • 17
  • 118
  • 172
BilalZ
  • 21
  • 1
  • 4
  • [tag:econnrefused] means axios successfully reached the machine mentioned in that IP address, but found no server running on the port you want. Are you sure you want to use `http:` rather than `https:` to hit that web service? – O. Jones Jul 23 '22 at 11:39
  • @O.Jones Yes, I am sure. The documentation provided for the API is all ```http:```, I have made requests using ```http:``` to the endpoint using postman successfully. – BilalZ Jul 23 '22 at 12:27

1 Answers1

1

The problem was I did not have an httpAgent so it was not using the proxy for http requests, which is why the API server was probably refusing connection. Since it has the static IP in its whitelist and not our server IP.

const agent = new HttpsProxyAgent(process.env.STATIC_URL!);
const baseOptions: AxiosRequestConfig = {
    proxy: false,
    httpsAgent: agent,
    httpAgent: agent,
};
const instance = axios.create(baseOptions);
const response = await instance(req.body);

res.send({ success: true, response: response.data });

adding the httpAgent fixed the issue.

BilalZ
  • 21
  • 1
  • 4