json - Azure Functions 路由与未知 URL 绑定(bind)

标签 json azure azure-functions

我正在尝试构建 function.json 文件,其中 url 具有我们不知道的自定义结尾。该客户结尾可能包含正斜杠,因此我不能保证这将是一个参数。我当前的代码:

    {
    "bindings": [
      {
        "authLevel": "function",
        "type": "httpTrigger",
        "direction": "in",      
        "route": "{param1}/customer/{param2}/{restOfUrl}",
        "name": "req",
        "methods": [
          "get"
        ]
      },
      {
        "type": "http",
        "direction": "out",
        "name": "res"
      }
    ],
    "scriptFile": "../dist/src/handlers/myScript.js"
  }

例如,当网址为:

时,这可以正常工作
...123/customer/456/rest-of-url

但是,如果网址的其余部分包含正斜杠,例如:

...123/customer/456/rest/of/url

我收到 404 未找到。

如果 url 未知并且可能包含正斜杠/,如何正确定义路由?

最佳答案

尝试建议的解决方案后,我发现 this Azure 文档中的 doc。解决方案是 * 剩余参数,它将路径的其余部分作为字符串返回。更改如下所示:

 "route": "{param1}/customer/{param2}/{*restOfUrl}"

关于json - Azure Functions 路由与未知 URL 绑定(bind),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72601881/

相关文章:

Azure 函数服务总线队列触发器 - "A host error has occurred. System.Private.Uri: Value cannot be null. Parameter name: uriString."

javascript - D3.js - 使用 json 中的嵌套数组绘制图像

c# - 使用 JSON 发布请求,但服务器端有 Request.Form.Count == 0

python - Python 中的 JSON.loads() ValueError 额外数据

PHP 访问私有(private) Azure 存储容器

Azure函数服务总线触发器并发

azure - Azure 函数 v1 的 Http 响应中不存在内容长度 header

php - 这是什么数据,能转成JSON吗

Azure Devops 运行结果步骤和运行摘要详细信息附件 API

c# - 该请求无权执行该操作。 Azure blob客户端