【问题标题】:NodeJS - How to get the HTTP header of a SOAP webservice's responseNodeJS - 如何获取 SOAP Web 服务响应的 HTTP 标头
【发布时间】:2016-08-01 23:21:41
【问题描述】:

在 NodeJS 中使用“soap”包使用 SOAP Web 服务时。像这样:

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 Header 中的 Cookie 参数。

这是 Node/Express 可以做到的吗?或者我需要另一个包来实现这个吗?

提前致谢。

【问题讨论】:

    标签: node.js web-services http soap http-headers


    【解决方案1】:

    NodeJS SOAP 模块在调用方法时存储针对客户端的最后响应标头,因此只需在回调中访问它:

    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);        
      });
    });
    

    【讨论】:

      【解决方案2】:

      我遇到了同样的问题,并且已经研究了一段时间。我在可以看到 cookie 的地方取得了一些进展,但它们并没有像我预期的那样完全通过。我不确定我是否做错了什么,或者它特定于我试图命中的服务 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);
          });
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2016-09-21
        • 1970-01-01
        • 2012-03-20
        • 2021-05-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多