2

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?

4

2 回答 2

14

在设置为已设置的请求对象的soap.createClient()选项中,使用.'request''proxy'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) {
于 2016-07-06T18:47:06.480 回答
3

好吧,在查看代码后,我发现您可以将代理声明为环境变量。

process.env.http_proxy = 'http://proxyhost:proxyport';

这行得通!

于 2016-03-18T13:12:21.580 回答