我需要发回一个具有以下特征的确认响应:
我的尝试:
null
function handleMessage(req, res){
let otaRequestBuffer = [];
req.on('readable', () => {
let data;
while (data = req.read()) {
otaRequestBuffer.push(data.toString());
}
});
req.on('end', () => {
let otaRequest = otaRequestBuffer.join('');
try {
let parser = new DOMParser();
let xmlDoc = parser.parseFromString(otaRequest, "text/xml");
let soapHeader = parseSoapHeader(xmlDoc);
const soapAction = req.headers['soapaction'].toString();
const ack = `<?xml version='1.0' encoding='utf-8'?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope">
<env:Header>
<htnga:CorrelationID xmlns:htnga="http://htng.org/PWSWG/2007/02/AsyncHeaders">${soapHeader.correlationId}</htnga:CorrelationID>
<htnga:RelatesToCorrelationID xmlns:htnga="http://htng.org/PWSWG/2007/02/AsyncHeaders">${soapHeader.correlationId}</htnga:RelatesToCorrelationID>
</env:Header>
<env:Body>
<ns:HTNG_AcknowledgeReceipt xmlns:ns="http://htng.org/2014B"/>
</env:Body>
</env:Envelope>`
res.sendStatus(200);
res.write(ack);
} catch (error) {
console.log(error);
}
});
null
但这只发送OK。如何发送有效载荷/主体和HTTPS状态代码200。
谢谢你的帮助。
下面是API提供商文档的截图:
默认情况下,res.send()的状态代码为200,但对于其他状态代码,可以使用
res.status(403).send("You are not authorised to view this")