【发布时间】:2021-09-02 21:31:03
【问题描述】:
我很惊讶我找不到答案,但我有一个 Azure 函数(HTTP 触发器),我只是想将内容反序列化为对象。以前使用 V1 我能够做到这一点,
函数 V1
[FunctionName("RequestFunction")]
public static async Task<HttpResponseMessage> Run([HttpTrigger(AuthorizationLevel.Function, "post", Route = null)]HttpRequestMessage req, TraceWriter log)
{
// Successful deserialization of the content
var accountEvent = await req.Content.ReadAsAsync<AccountEventDTO>();
// Rest of the function...
}
但现在 V2 看起来更像这样,
函数 V2
[FunctionName("RequestFunction")]
public static async Task<IActionResult> Run([HttpTrigger(AuthorizationLevel.Function, "get", "post", Route = null)]HttpRequest req, ILogger log)
{
// Content doesn't exist on HttpRequest anymore so this line doesn't compile
var accountEvent = await req.Content.ReadAsAsync<AccountEventDTO>();
// Rest of the function...
}
我可以让主体从 HttpRequest 对象访问流,但我不确定如何将其转换为预期的对象。有什么想法吗?
【问题讨论】:
标签: c# azure-functions