Search code examples
node.jssoapsoap-clientnode-soap

Calling SOAP API through proxy with node-soap client


I am using the node-soap module and it's working fine, except when I am working behind a proxy. I can't manage to find the way to set that proxy so I can request the API.

soap.createClient(url, function(err, client) {
      client.MyFunction(args, function(err, result) {
          console.log(result);
      });
});

It's written in the docs :

The options argument allows you to customize the client with the following properties:

request: to override the request module.
httpClient: to provide your own http client that implements request(rurl, data, callback, exheaders, exoptions).

Is that the way to go?


Solution

  • In the soap.createClient() options set 'request' to a request object that has 'proxy' set using request.defaults().

    let request = require('request');
    let request_with_defaults = request.defaults({'proxy': PROXY_URL, 'timeout': 5000, 'connection': 'keep-alive'});
    let soap_client_options = {'request': request_with_defaults};
    soap.createClient(WSDL_URL, soap_client_options, function(err, client) {