NodeJS - 如何获取SOAP web服务的响应的HTTP头
问题描述:
当使用'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可以做些什么吗?或者是否有另一个我需要实现的包?
在此先感谢。
答
我遇到了同样的问题,并且一直在努力一段时间。我已经取得了一些进展,我可以在哪里看到这些饼干,但他们并没有完全按照我的预期进行。我不确定我是否做错了什么,或者它是特定于我尝试访问的服务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);
});
});
答
的肥皂的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);
});
});