Azure Functions 可以返回 XML 吗? [英] Can Azure Functions return XML?
问题描述
寻找从 Azure 函数返回 XML 的 Node.js 示例.我下面的代码返回 xml 字符串,但响应 Content-Type 设置为 text/plain;charset=utf-8 而不是 text/xml;charset=utf-8
Looking for a Node.js example of returning XML from an Azure Function. The code that I have below returns the string of xml, but the response Content-Type is set to text/plain; charset=utf-8 instead of text/xml; charset=utf-8
index.js
module.exports = function(context, req) {
var xml = '<?xml version="1.0" encoding="UTF-8"?><Response><Say>Azure functions!</Say></Response>';
context.res = {
contentType: 'text/xml',
body: xml
};
context.done();
};
这是绑定.
function.json
{
"bindings": [
{
"authLevel": "function",
"type": "httpTrigger",
"direction": "in",
"name": "req"
},
{
"type": "http",
"direction": "out",
"name": "res"
}
],
"disabled": false
}
推荐答案
Mark,
绝对的!您很接近,但您可以看到如何在响应中设置内容类型的示例 这里.
Absolutely! You were close, but you can see an example of how you can set the content type on the response here.
下一个版本还有一个修复程序,它将启用适当的内容协商,这将消除在许多情况下明确设置该内容的需要.
There's also a fix with the next release that will enable proper content negotiation, which would eliminate the need to explicitly set that content in many cases.
这篇关于Azure Functions 可以返回 XML 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!