从Azure PowerShell函数提供HTML页面

从Azure PowerShell函数提供HTML页面,powershell,azure,azure-functions,serverless,faas,Powershell,Azure,Azure Functions,Serverless,Faas,我尝试从AzurePowerShell函数提供HTML页面。我可以返回HTML,但我知道在哪里可以将内容类型设置为text/html,以便浏览器解释HTML 下面是一个用C#实现的方法: 但是在PowerShell函数中,我只使用Out filecmdlet返回文件,没有设置内容类型的选项。下面是一个hello world示例: # POST method: $req $requestBody = Get-Content $req -Raw | ConvertFrom-Json $name =

我尝试从AzurePowerShell函数提供HTML页面。我可以返回HTML,但我知道在哪里可以将内容类型设置为text/html,以便浏览器解释HTML

下面是一个用C#实现的方法:

但是在PowerShell函数中,我只使用
Out file
cmdlet返回文件,没有设置内容类型的选项。下面是一个hello world示例:

# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name

# GET method: each querystring parameter is its own variable
if ($req_query_name) 
{
    $name = $req_query_name 
}

$html = @'
<html>
<header><title>This is title</title></header>
<body>
Hello world
</body>
</html>
'@

Out-File -Encoding Ascii -FilePath $res -inputObject $html
#POST方法:$req
$requestBody=Get Content$req-Raw | convertfromjson
$name=$requestBody.name
#GET方法:每个querystring参数都是它自己的变量
if($req\u query\u name)
{
$name=$req\u query\u name
}
$html=@'
这是标题
你好,世界
'@
输出文件-编码Ascii-文件路径$res-输入对象$html
以下是响应在浏览器中的外观:


知道如何设置内容类型以便浏览器解释HTML吗?

您可以返回一个响应对象,其中包含属性
body
headers
status
isRaw
(可选):


您可以返回具有以下属性的响应对象:
body
headers
status
isRaw
(可选):


嗯,你可以用c设置内容类型吗?@4c74356b41我不明白你的问题。我想在Azure PowerShell函数中设置内容类型,而不是C。好吧,你可以用C设置内容类型?@4c74356b41我不明白你的问题。我想在Azure PowerShell函数中设置内容类型,而不是C#。哇,这很简单:D。非常感谢!你怎么知道的?@mikhail愿意分享来源吗?@4c74356b41我只有javascriptWow,这很简单:D。非常感谢!你怎么知道的?@mikhail愿意分享源代码吗?@4c74356b41我只有javascript版本
# POST method: $req
$requestBody = Get-Content $req -Raw | ConvertFrom-Json
$name = $requestBody.name

# GET method: each querystring parameter is its own variable
if ($req_query_name) 
{
    $name = $req_query_name 
}

$html = @'
<html>
<header><title>This is title</title></header>
<body>
Hello world
</body>
</html>
'@

Out-File -Encoding Ascii -FilePath $res -inputObject $html
$result = [string]::Format('{{ "status": 200, "body": "{0}", "headers": {{ 
"content-type": "text/html" }} }}', $html)
Out-File -Encoding Ascii $res -inputObject $result;