gpt4 book ai didi

node.js - Azure函数: NodeJS - HTTP Response Renders as XML rather than HTML

转载 作者:太空宇宙 更新时间:2023-11-03 22:41:13 25 4
gpt4 key购买 nike

我有一个带有 function.json 的 Node azure 函数,如下所示:

{
"disabled": false,
"bindings": [
{
"name": "req",
"type": "httpTrigger",
"direction": "in",
"methods": [ "get" ]
},
{
"name": "res",
"type": "http",
"direction": "out"
}
]
}

我希望函数返回 html 来给我一个像这样的页面: enter image description here

但是,当我像这样编写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();
};

我得到这个:

enter image description here

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com