Azure 上的无服务器 PowerShell 脚本 return html 在浏览器中显示

serverless PowerShell script on azure to return html to show in browser

我在 Azure 无服务器中编写了一个 PowerShell 脚本 returns 一些 html

当使用来自 Firefox 或 Chrome 的脚本时,传输的 html 文档在浏览器中按预期打开,但是当使用 Microsoft 的浏览器 Edge 或 Internet Explorer 时,传输的 html 文件被下载为一个文件,这绝对不是我们想要的。

我尝试修改内容配置,但没有成功。

我应该在脚本中修改什么以使 IE 和 Edge 正确显示 html 内容?

这是制作 html 文档的部分代码。

foreach ($container in $containers | Sort-Object -Property Name -Descending )
{
    $uri = "list?name=$($container.Name)"
    $HTML += "<li><a href=`"$($uri)`">$($container.Name)</a></li>"+ "`r`n"
}

$HTML += "</ul>"+ "`r`n"
$HTML += "  </body></html>"


$status = [HttpStatusCode]::OK
$body = $HTML

# Associate values to output bindings by calling 'Push-OutputBinding'.
Push-OutputBinding -Name Response -Value ([HttpResponseContext]@{
    StatusCode = $status
    Body = $body
    headers = @{'content-type'='text\html'}
})

似乎是您本地浏览器的设置,不是编码问题。您需要更改浏览器设置才能解决此问题:

问题似乎是 header

我从

更改了 headers
@{'content-type'='text\html'} 

headers = @{'content-type'='text/html'}

现在显示正确,感谢@John Hanley 提到 'validation' 作为验证器。w3.org 抱怨 header 拒绝解析文档