0

我使用 Azure 门户创建了一个函数应用。我检查了 POST 和 OPTIONS 作为允许的方法。我删除了默认的 CORS 设置并允许 *. 现在,当我使用 REST 客户端发出 OPTIONS 请求时,我收到一个错误返回。我检查了日志,发现以下内容。我的问题:听起来我的函数可能正在执行,当没有发现授权标头和/或有效负载时,它会引发错误。也许我不明白 OPTIONS 请求。在 Azure 门户函数应用中防止这种情况发生的选项有哪些?

TIA 寻求帮助。

2019-05-17T09:16:26.479 [Info] Executing HTTP request: {
  "requestId": "38609669-59f4-4ded-9685-ef67af3c2909",
  "method": "OPTIONS",
  "uri": "/api/ProcessEntries"
}
2019-05-17T09:16:26.479 [Info,ProcessEntries] Function started (Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.479 [Info,ProcessEntries] Executing 'Functions.ProcessEntries' (Reason='This function was programmatically called via the host APIs.', Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.495 [Error] A ScriptHost error has occurred
2019-05-17T09:16:26.495 [Error] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.526 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries. Microsoft.Azure.WebJobs.Script: One or more errors occurred. Anonymously Hosted DynamicMethods Assembly: Cannot perform runtime binding on a null reference.
2019-05-17T09:16:26.573 [Error,ProcessEntries] Exception while executing function: Functions.ProcessEntries
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function completed (Failure, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6, Duration=87ms)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Executed 'Functions.ProcessEntries' (Failed, Id=41b4691d-98ec-432f-8e6e-de1e1dcd13b6)
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.573 [Error,ProcessEntries] Function had errors. See Azure WebJobs SDK dashboard for details. Instance ID is '41b4691d-98ec-432f-8e6e-de1e1dcd13b6'
2019-05-17T09:16:26.573 [Error,ProcessEntries] Cannot perform runtime binding on a null reference
2019-05-17T09:16:26.588 [Error] {"id":"eada812b-1530-4d26-85e3-4c6e6e243f01","requestId":"38609669-59f4-4ded-9685-ef67af3c2909","statusCode":500,"errorCode":0,"message":"An error has occurred. For more information, please check the logs for error ID eada812b-1530-4d26-85e3-4c6e6e243f01"}
2019-05-17T09:16:26.588 [Error] Cannot perform runtime binding on a null reference


4

2 回答 2

0

也许回答我自己的问题(这并不是真正的答案)让我以更简洁的方式发布后续内容。

我不明白为什么选项请求会寻找要绑定的东西。我可以理解为什么我的功能会,是的。它确实与某些存储帐户的东西有联系,并且确实需要有效负载。但是为什么选项请求会关心其中的任何一个呢?它是否试图执行该功能?


{
  "bindings": [
    {
      "authLevel": "anonymous",
      "name": "req",
      "type": "httpTrigger",
      "direction": "in",
      "methods": [
        "post",
        "options"
      ]
    },
    {
      "name": "$return",
      "type": "http",
      "direction": "out"
    },
    {
      "type": "table",
      "name": "outShazamPayloadsTable",
      "tableName": "czShazamPayloadsTable",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    },
    {
      "type": "queue",
      "name": "outputQueueItem",
      "queueName": "czshazamqueue",
      "connection": "czshazam19storageaccount_STORAGE",
      "direction": "out"
    }
  ],
  "disabled": false
}

于 2019-05-17T12:52:46.550 回答
0

万一以后有人遇到这个...

原来问题是即使发送了 OPTIONS 请求,我的函数应用程序也正在执行。我没想到的是。它正在轰炸,因为它没有发送任何有效载荷。由于项目的性质,我知道总会有一个带有 POST 的有效负载,并且从未考虑过 OPTIONS 请求也会执行该代码。一旦我在我的函数中进行了一些空检查,一切都很好,我开始接收状态 = 200 的 OPTIONS 请求。

我想我应该记得从来没有什么是确定的。

于 2019-05-17T18:33:37.580 回答