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

时间:2016-03-17 10:19:51

标签: node.js soap soap-client node-soap

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

s3cmd put ~/Desktop/filename.ext  s3://mybucket -f

它写在文档中:

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

这是要走的路吗?

2 个答案:

答案 0 :(得分:12)

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

答案 1 :(得分:3)

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

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

这有效!

相关问题