【问题标题】:serverless PowerShell script on azure to return html to show in browserazure 上的无服务器 PowerShell 脚本返回 html 以在浏览器中显示
【发布时间】:2020-05-06 17:18:50
【问题描述】:

我在 Azure serverless 中编写了一个 PowerShell 脚本,它返回一些 html

当使用Firefox或Chrome的脚本时,传输的html文档在浏览器中按预期打开,但是当使用微软的浏览器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'}
})

【问题讨论】:

  • 显示正在生成的实际 HTML。 curl 是一个很好的工具。根据问题中显示的详细信息,很可能您的 HTML 不完整。
  • html body 不错,但是 'text\html' 应该是 'text/html'!

标签: html azure powershell serverless


【解决方案1】:

问题似乎是标题

我从

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

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

现在它显示正确,感谢@John Hanley 提到“验证”,因为 validator.w3.org 抱怨标题拒绝解析文档

【讨论】:

    【解决方案2】:

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

    https://stackoverflow.com/a/17968940/1384539

    【讨论】:

    • 它发生在多台安装了全新 Windows 10 的计算机上。无需更改任何设置:)
    猜你喜欢
    • 1970-01-01
    • 2017-12-23
    • 1970-01-01
    • 1970-01-01
    • 2014-08-17
    • 1970-01-01
    • 1970-01-01
    • 2021-03-20
    相关资源
    最近更新 更多