首页 > 解决方案 > AZURE API 管理 - 对象引用未设置为对象的实例

问题描述

Azure API 管理带有响应“System.NullReferenceException:对象引用未设置为对象的实例”。

MyFunction.cs:line 61 中的 MyFunction.Run(HttpRequest req, ILogger log)

方法签名

公共异步任务运行([HttpTrigger(AuthorizationLevel.Anonymous,“get”,Route = null)] HttpRequest req,ILogger 日志)

对不起大家,我是 Azure APIM 的新成员!

当我将以下请求正文中的 JSON 发送到 c# azure function API 时,一切正常!!

{
    "Id":40,
    "status":"Doing",
    "startedDateTime":"2019-10-17T17:50:44.1314885Z"
}

但是,当我通过 Azure API 管理将其发送到无服务器 Azure 函数 API 微服务时,我收到错误消息“对象引用未设置为对象的实例”。

我的 Azure 函数在标头中只有 APIM 密钥,没有其他内容;我刚刚创建了 APIM 消耗以用作端点,我只有 CORS 策略并尝试用于测试,但我遇到了同样的问题

<policies>
    <inbound>
        <base />
        <choose>
            <when condition="@(context.Request.Body != null)">
                <set-body template="liquid">
                    <value>@(context.Request.Body.As<JObject>(preserveContent: true).Value<string>())</value>
                </set-body>
            </when>
        </choose>
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>

有人可以帮助我吗?相同的解决方案是什么?

标签: .net-coreazure-functionsmicroservicesazure-api-managementserverless-architecture

解决方案


推荐阅读