gpt4 book ai didi

c# - 如何在 Azure Functions 中使用 Http 触发器进行模型绑定(bind)?

转载 作者:行者123 更新时间:2023-12-03 01:38:18 24 4
gpt4 key购买 nike

我需要创建一个响应 HTTP POST 并利用集成模型绑定(bind)的 Azure 函数。

如何修改这个

    [FunctionName("TokenPolicy")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "TokenPolicy/{IssuerID}/{SpecificationID}")]HttpRequestMessage req, string IssuerID, string specificationID, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request. TokenPolicy");

// Fetching the name from the path parameter in the request URL
return req.CreateResponse(HttpStatusCode.OK, "data " + specificationID);
}

以这样的方式,我的客户端 POST 是对象,并且我有正常的 ASP.NET 样式模型绑定(bind)?

最佳答案

基于 HTTP trigger from code 的文档,你可以简单地接受你自己的对象:

For a custom type (such as a POCO), Functions will attempt to parsethe request body as JSON to populate the object properties.

public class MyModel
{
public int Id { get; set; }
public string Name { get; set; }
}

[FunctionName("TokenPolicy")]
public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = "TokenPolicy/{IssuerID}/{SpecificationID}")]MyModel myObj, string IssuerID, string specificationID, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request. TokenPolicy");


// Do something your your object

return new HttpResponseMessage(HttpStatusCode.OK);
}

关于c# - 如何在 Azure Functions 中使用 Http 触发器进行模型绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44660314/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com