CDATA肥皂请求

时间:2019-07-17 13:57:43

标签: node.js xml soap google-cloud-functions node-modules

我正在使用以下库(https://www.npmjs.com/package/soap)将肥皂请求发送到api。

请求应如下所示:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xmlns:tns="https://www.cashweb.nl/?api/3.0" xmlns:ns="https://www.cashweb.nl/?api/3.0">
    <soap:Body>
        <tns:Import>
            <relatie></relatie>
            <email></email>
            <pass></pass>
            <importData>
            <![CDATA[<?xml version="1.0">
                <CASH>
                    <R3600>
                        <F3600>30053942</F3600>
                        <F4102>011</F4102>
                    </R3600>
                </CASH>]]>
            </importData>
            <administration>
                <admCode>Bboy</admCode>
                <admMap/>
            </administration>
            <formaat>0</formaat>
        </tns:Import>
    </soap:Body>
</soap:Envelope>

我遇到的问题是我无法通过模块将CDATA标记放入请求中。

在您可以看到我的函数的下面,我尝试了JSON args输入以及直接XML输入,但无法使其正常工作。

exports.test = functions.region('europe-west1').https.onRequest((request, response) => {
    const servicebonnummer = "30053942";
    const servicestatus = "011";

    const url = '';
    const args = { relatie: '', email: '', pass: '', importData: {undefined: '' CASH: { R3600: { F3600: '30053942', F4102: '011' } } }, administration: { admCode: 'Bboy', admMap: '' }, formaat: '0' }
    // const args = {
    //     _xml: "<relatie>4841</relatie> <email></email> <pass></pass> <importData> <![CDATA[<?xml version=\"1.0\"> <CASH> <R3600> <F3600>30053942</F3600> <F4102>011</F4102> </R3600> </CASH>]]> </importData> <administration> <admCode>Bboy</admCode> <admMap/> </administration> <formaat>0</formaat>\"}"
    // }

    soap.createClient(url, function (err, client) {
        if (err) {
            response.status(500)
            response.send("error creating client")
        }
        client.Import(args, function (err, result, rawResponse, soapHeader, rawRequest) {
            // result is a javascript object
            // rawResponse is the raw xml response string
            // soapHeader is the response soap header as a javascript object
            // rawRequest is the raw xml request string
            if (err) {
                response.status(500)
                response.send(err + " " + rawRequest)
            }
            response.status(200)
            response.send(rawRequest)
        })
    });

});

我更喜欢使用JSON参数输入。有人可以帮我吗?

0 个答案:

没有答案