通过带有节点肥皂客户端的代理调用 SOAP API



我正在使用node-soap模块并且它工作正常,除非我在代理后面工作。我无法找到设置该代理的方法,以便我可以请求 API。

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

它写在文档中:

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).

这是要走的路吗?

soap.createClient()选项中,'request'使用request.defaults()设置了'proxy'的请求对象。

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) {

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

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

这行得通!

最新更新