admin管理员组文章数量:1335106
I want to response this using node.js and express:
<set id="1" state="0" name="wd"/>
I tried:
xml = require('xml');
res.set('Content-Type', 'text/xml');
res.send(xml('<set id="1" state="0" name="wd"/>'));
But in Wireshark
i see that my response looks:
<set id="1" state="0" name="wd"/>
How to send my xml correctly?
I want to response this using node.js and express:
<set id="1" state="0" name="wd"/>
I tried:
xml = require('xml');
res.set('Content-Type', 'text/xml');
res.send(xml('<set id="1" state="0" name="wd"/>'));
But in Wireshark
i see that my response looks:
<set id="1" state="0" name="wd"/>
How to send my xml correctly?
Share Improve this question edited Mar 23, 2021 at 7:56 Rashomon 6,7924 gold badges39 silver badges80 bronze badges asked May 12, 2019 at 16:52 Kliver MaxKliver Max 5,29924 gold badges101 silver badges157 bronze badges3 Answers
Reset to default 4xml
package converts JS objects to xml (and you are passing a stringified xml). Not what you need. You need to parse the string containing xml to get actual xml data using libxmljs
.
I would try this:
const libxmljs = require("libxmljs");
let stringifiedXml = '<set id="1" state="0" name="wd"/>';
let xmlDoc = libxmljs.parseXml(stringifiedXml);
res.set('Content-Type', 'text/xml');
res.send(xmlDoc);
Try removing xml()
function. If you set Content-type
, the server would send response as xml.
In ExpressJs Simply add the content-type and send a valid XML document as the xmlContent
response.type('application/xml')
response.send(xmlContent)
本文标签: javascriptHow to response XML with nodejs expressStack Overflow
版权声明:本文标题:javascript - How to response XML with node.js express? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742382883a2464444.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论