2016-08-01 170 views
0

當使用'soap'包在NodeJS中使用SOAP web服務時。像這樣:NodeJS - 如何獲取SOAP web服務的響應的HTTP頭

var soap = require('soap'); 
var url = 'http://example.com/wsdl?wsdl'; 
var args = {name: 'value'}; 
clientsoap.createClient(url, function(err, client) { 
    client.MyFunction(args, function(err, result, raw, soapHeader) { 
     console.log(result); 
    }); 
}); 

如何獲得對MyFunction的響應的HTTP標頭?具體來說,我需要HTTP頭中的Cookie參數。

Node/Express可以做些什麼嗎?或者是否有另一個我需要實現的包?

在此先感謝。

回答

0

我遇到了同樣的問題,並且一直在努力一段時間。我已經取得了一些進展,我可以在哪裏看到這些餅乾,但他們並沒有完全按照我的預期進行。我不確定我是否做錯了什麼,或者它是特定於我嘗試訪問的服務WSDL。但這裏是我的解決方案...

soap.createClient(pathOrUrlToWSDL, function(err, client) { 
    client.myFunction(args, function(err, result, raw, soapHeader) { 
     console.log(err, result, raw, soapHeader); 
    }); 

    // -- should reach the response before the callback in client.myFunction() 
    client.on('response', function(envelope, message) { 
     // -- couldn't find documentation on this function, so I just named the variables 'envelope' and 'message' 
     console.log(message.headers); 
    }); 
}); 
1

的肥皂的NodeJS模塊存儲調用方法時,所以才訪問它在你的回調對客戶端的最後響應頭:

var soap = require('soap'); 
var url = 'http://somewhere.com?wsdl'; 
var args = {name: 'value'}; 
soap.createClient(url, function(err, client) { 
    client.myFunction(args, function(err, result) { 
    console.log(client.lastResponseHeaders);   
    }); 
});