我有一个带有 function.json 的 Node azure 函数,如下所示:
{
"disabled": false,
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [ "get" ]
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}
但是,当我像这样编写index.js时:
module.exports = function (context, sentimentTable) {
context.res = {
body: "<!DOCTYPE html> <html> <head> </head> <body> Hello World </body> </html>",
contentType: "text/html"
};
context.done();
};
我得到这个:
Azure Functions 可以返回 html 吗?
最佳答案
必须是“Content-Type”并且您以这种方式指定 header
context.res = {
body: '...',
headers: {
'Content-Type': 'text/html; charset=utf-8'
}
}
请参阅 AzureServerless.com 上的这篇博文 - http://azureserverless.com/2016/11/12/a-html-nanoserver/
关于node.js - Azure函数: NodeJS - HTTP Response Renders as XML rather than HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42087283/