0

我有路径“/todo/{id}”,我想获取 Id 路径参数。

        [Function("Run")]
        public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
            Route = "todo/{id}")] HttpRequestData req,
            FunctionContext executionContext)
        {
            var logger = executionContext.GetLogger("GetTodo");
            logger.LogInformation("C# HTTP trigger function processed a request.");

            var response = req.CreateResponse(HttpStatusCode.OK);
            response.Headers.Add("Content-Type", "text/plain; charset=utf-8");

            response.WriteString("Welcome to Azure Functions!");

            return response;
        }

如何访问 Id?

提前致谢!

4

1 回答 1

1

可以包含绑定输入。

您可以通过在方法参数中放置变量来获取路径参数。

        [Function("Run")]
        public static HttpResponseData Run([HttpTrigger(AuthorizationLevel.Anonymous, "get",
            Route = "todo/{id}")] HttpRequestData req, string id,
            FunctionContext executionContext) 
{
            var logger = executionContext.GetLogger("GetTodo");
            logger.LogInformation("C# HTTP trigger function processed a request.");

            logger.LogInformation("This is the id - {id}", id);
}
于 2021-10-13T06:09:43.930 回答