2016-03-17 118 views
2

我正在使用node-soap模塊,它工作正常,除了當我在代理之後工作。我無法設法找到設置該代理的方式,因此我可以請求API。通過代理與節點肥皂客戶端調用SOAP API

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

這是寫在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). 

是不是要走的路?

回答

10

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

那麼,在查看代碼後,我發現您可以將您的代理聲明爲環境變量。

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

This Works!