【问题标题】:In node-soap, how can I see/debug the generated XML SOAP request?在 node-soap 中,如何查看/调试生成的 XML SOAP 请求?
【发布时间】:2017-02-08 16:57:00
【问题描述】:

我尝试像这样使用 node-soap 模块:

const soap = require('soap');

soap.createClient('some-wsdl-url', function(err, client) {
    const args = {
        'ValidateCustomerRequest': {
            'memberNumber': 12345
        }
    };

    client.ValidateCustomer(args, function(err, result) {
        console.log(result);
    });
});

现在我收到来自网络服务的“无效格式”响应。为了调试它,我非常想看看发送到 web 服务的实际 XML 是什么样子的。

这个我已经试过了:

require('request').debug = true

...another SO answer 中的建议。

但输出没有那么有用:

[ERROR] REQUEST { uri:
  Url { ... },
  method: 'GET',
  headers:
   { 'User-Agent': 'node-soap/0.18.0',
     Accept: 'text/html,application/xhtml+xml,application/xml,text/xml;q=0.9,*/*;q=0.8',
     'Accept-Encoding': 'none',
     'Accept-Charset': 'utf-8',
     Connection: 'close',
     Host: 'xxx' },
  followAllRedirects: true,
  body: null,
  callback: [Function] }

我在那里看不到我的“ValidateCustomerRequest”,并且正文为空。另外我想知道为什么方法是GET,不应该是POST吗?

那么这个调试输出看起来是否正常和/或是否有其他方法可以查看创建的 XML 请求?

【问题讨论】:

    标签: node.js soap


    【解决方案1】:

    我忽略了documentation的这一点:

    Client.lastRequest - 包含客户端日志记录的最后一个完整的 soap 请求的属性

    您可以在 web 服务调用的回调中记录这一点。所以上面的代码会是这样的:

    const soap = require('soap');
    
    soap.createClient('some-wsdl-url', function(err, client) {
        const args = {
            'ValidateCustomerRequest': {
                'memberNumber': 12345
            }
        };
    
        client.ValidateCustomer(args, function(err, result) {
            console.log(result);
            console.log('last request: ', client.lastRequest) // <-- here
        });
    });
    

    这将输出生成的 XML 请求。

    【讨论】:

    • 更多,客户端有 lastResponse 以及 lastResponse 和 lastRequest 的 Headers
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-17
    • 2019-02-02
    • 2012-09-04
    相关资源
    最近更新 更多