如何使用xmlrpc将参数作为对象传递 - 节点模块(github.com/baalexander/node-xmlrpc)

时间:2017-04-14 03:51:33

标签: node.js xml-parsing xml-rpc

实际上需要使用xmlrpc节点模块github.com/baalexander/node-xmlrpc传递一个xml参数作为对象;

客户来电是:

  

client.methodCall(' anAction',[' aParam'],函数(错误,值){})

需要用这样的东西替换aParam:

<?xml version='1.0'?>
<methodCall>
<methodName>GetBalanceAndDate</methodName>
<params>
<param>
<value><struct>
<member>
<name>originTransactionID</name>
<value><string>90000001</string></value>
</member>
<member>
<name>originHostName</name>
<value><string>PADFVPZ452P01</string></value>
</member>
<member>
<name>subscriberNumber</name>
<value><string>24107482594</string></value>
</member>
<member>
<name>subscriberNumberNAI</name>
<value><int>1</int></value>
</member>
<member>
<name>originTimeStamp</name>
<value><dateTime.iso8601>20140626T14:53:53+0100</dateTime.iso8601></value>
</member>
<member>
<name>originNodeType</name>
<value><string>EXT</string></value>
</member>
</struct></value>
</param>
</params>
</methodCall>

我试过了:

var req1 = {
value: {
struct:{
member:{$name:'originTransactionID',value:'90000001'},
mamber:{$name:'originHostName',value:'GAGAPOPAAPZP01'},
member:{$name:'subscriberNumber',value:'24104151708'},
member:{$name:'subscriberNumberNAI',value: 1},
member:{$name:'originTimeStamp', value: new Date()},
member:{$name:'originNodeType', value:  'EXT'}
}
}
};



client.methodCall('GetBalanceAndDate', [req1], function (error, value) {})

但有错误: faultString:&#39;非法请求消息&#39;

关于它如何运作的任何想法???

1 个答案:

答案 0 :(得分:0)

尝试将xml作为参数传递,我这样做:

const request = `
<?xml version="1.0"?>
<methodCall>
    <methodName>CheckBal</methodName>
    <params>
        <param>
            <value>
                <struct>
                    <member>
                        <name>RMID</name>
                        <value><string>${rmid}</string></value>
                    </member>
                    <member>
...
</methodCall>`;

client.methodCall('CheckBal', [request], (error, value) => {
    console.log(value);
});