2017-11-25 15 views
-1

私はlibを使用して、nodejsアプリからwcfサービスを休止するためのデータを投稿しました。私はxmlデータ型でこれを行いますが、xmlの代わりにjsonデータを使用します:Nodejs - JsonでRest Wcfサービスを呼び出す

"jsonデータでxmlnsプロパティを書き込む方法は?"あなたがxmlbuilderを使用している場合

request(
    { 
     method: 'POST', 
     url: 'http://localhost:8590/Service1.svc/auth', 
     body: '<RequestData xmlns="http://localhost:8590/mPlayer">\n' + 
     ' <details>Ashu|29|7 Years|.NET</details>\n' + 
     '</RequestData>', 
     headers: {'Content-Type': 'text/xml'}, 
    }, 
    function (error, response, body) { 
     if (!error && response.statusCode == 200) { 
      console.log(body) 
     } 
    } 
); 

答えて

0

、あなたはここではXMLであるあなたが

<?xml version="1.0" encoding="utf-8"?><RequestData xmlns="http://localhost:8590/mPlayer"><details>Ashu|29|7 Years|.NET</details></RequestData> 
を必要とし、この

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) 

のようなJSONを作成することができます

関連する問題