首页 > 解决方案 > Azure Function v1 - 无法使用 PowerShell 获取 POST 正文内容

问题描述

我创建了一个运行时集为 64 位的 Azure Function v1 (PowerShell)。

我的 Azure Function 应该使用 PnP 在我的 SharePoint 网站上执行一些操作。

我已经在modules文件夹上上传了 DLL,并且在函数启动时它们已正确加载。然后我尝试调用我的函数,在我的 POST 调用中将此 JSON 作为正文发送:

{
"name":"Test1"
}

我的功能(我已删除所有 SharePoint PnP 命令)是这个:

using namespace System.Net
param($Request, $TriggerMetadata)
$requestBody = Get-Content $Request -Raw | ConvertFrom-Json
$name = $requestBody.name
Write-Host $name

每次我运行该函数时,我都会收到一个错误 500 的输出:

{
  "id": "xxxxxxxxxx",
  "requestId": "xxxxxxxxxxxxxxx",
  "statusCode": 500,
  "errorCode": 0,
  "message": "Exception while executing function: Functions.MyFunction-> PowerShell script error -> Cannot bind argument to parameter 'Path' because it is null."
}

我认为可以参考,Get-Content $Request但我不知道如何修复此代码以使其正常工作。

标签: azurepowershellazure-functions

解决方案


如果您使用的是 Azure Functions v1(根据您的标题),这就是原因。v2 或更高版本支持 Powershell:

在此处输入图像描述


推荐阅读