使用node-soap客户端通过代理调用SOAP API

kra*_*kig 2 soap soap-client node.js node-soap

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

soap.createClient(url, function(err, client) {
      client.MyFunction(args, function(err, result) {
          console.log(result);
      });
});
Run Code Online (Sandbox Code Playgroud)

它写在文档中:

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).
Run Code Online (Sandbox Code Playgroud)

这是要走的路吗?

小智 13

在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) {
Run Code Online (Sandbox Code Playgroud)