Node.js Nodejs-使用Json调用Rest Wcf服务

Node.js Nodejs-使用Json调用Rest Wcf服务,node.js,wcf,request,Node.js,Wcf,Request,我使用lib将数据从nodejs应用程序发布到rest wcf服务。我使用xml数据类型执行此操作,但我将使用json数据代替xml: “我不知道如何在json数据中编写xmlns属性?” 请求( { 方法:“POST”, 网址:'http://localhost:8590/Service1.svc/auth', 正文:'\n'+ “Ashu | 29 | 7年|.NET\n”+ '', 标题:{'Content-Type':'text/xml'}, }, 功能(错误、响应、正文){ 如果(!e

我使用lib将数据从nodejs应用程序发布到rest wcf服务。我使用xml数据类型执行此操作,但我将使用json数据代替xml:

“我不知道如何在json数据中编写xmlns属性?”

请求(
{
方法:“POST”,
网址:'http://localhost:8590/Service1.svc/auth',
正文:'\n'+
“Ashu | 29 | 7年|.NET\n”+
'',
标题:{'Content-Type':'text/xml'},
},
功能(错误、响应、正文){
如果(!error&&response.statusCode==200){
控制台日志(正文)
}
}
);

如果您使用的是
xmlbuilder
,您可以像这样创建json

const xmlbuilder = require('xmlbuilder')

const req = {
    RequestData: {
        '@xmlns': 'http://localhost:8590/mPlayer',
        details: 'Ashu|29|7 Years|.NET'
    }
}

const body = xmlbuilder.create(req, { encoding: 'utf-8' }).end()

console.log(body)
这是您需要的xml

<?xml version="1.0" encoding="utf-8"?><RequestData xmlns="http://localhost:8590/mPlayer"><details>Ashu|29|7 Years|.NET</details></RequestData>
Ashu | 29 | 7年| NET
<?xml version="1.0" encoding="utf-8"?><RequestData xmlns="http://localhost:8590/mPlayer"><details>Ashu|29|7 Years|.NET</details></RequestData>