<i id='VSF7g'><tr id='VSF7g'><dt id='VSF7g'><q id='VSF7g'><span id='VSF7g'><b id='VSF7g'><form id='VSF7g'><ins id='VSF7g'></ins><ul id='VSF7g'></ul><sub id='VSF7g'></sub></form><legend id='VSF7g'></legend><bdo id='VSF7g'><pre id='VSF7g'><center id='VSF7g'></center></pre></bdo></b><th id='VSF7g'></th></span></q></dt></tr></i><div id='VSF7g'><tfoot id='VSF7g'></tfoot><dl id='VSF7g'><fieldset id='VSF7g'></fieldset></dl></div>
    • <bdo id='VSF7g'></bdo><ul id='VSF7g'></ul>

      <legend id='VSF7g'><style id='VSF7g'><dir id='VSF7g'><q id='VSF7g'></q></dir></style></legend>
    1. <small id='VSF7g'></small><noframes id='VSF7g'>

      <tfoot id='VSF7g'></tfoot>

      Azure Functions 模型绑定

      时间:2023-10-05

        1. <small id='c1RrT'></small><noframes id='c1RrT'>

              <bdo id='c1RrT'></bdo><ul id='c1RrT'></ul>
                  <tbody id='c1RrT'></tbody>
              • <tfoot id='c1RrT'></tfoot>
                <legend id='c1RrT'><style id='c1RrT'><dir id='c1RrT'><q id='c1RrT'></q></dir></style></legend>

                <i id='c1RrT'><tr id='c1RrT'><dt id='c1RrT'><q id='c1RrT'><span id='c1RrT'><b id='c1RrT'><form id='c1RrT'><ins id='c1RrT'></ins><ul id='c1RrT'></ul><sub id='c1RrT'></sub></form><legend id='c1RrT'></legend><bdo id='c1RrT'><pre id='c1RrT'><center id='c1RrT'></center></pre></bdo></b><th id='c1RrT'></th></span></q></dt></tr></i><div id='c1RrT'><tfoot id='c1RrT'></tfoot><dl id='c1RrT'><fieldset id='c1RrT'></fieldset></dl></div>
                本文介绍了Azure Functions 模型绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我创建了一个 Azure 函数并在本地运行它:

                I've created an Azure Function and I'm running it locally:

                [FunctionName("HttpTriggerCSharpSet")]
                public static async Task<HttpResponseMessage> Set([HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)] MyDocument req, TraceWriter log)
                {
                   // ...
                }
                

                请注意,MyDocument 是第一个参数,而不是 HttpRequestMessage.我在文档中读到这种方法应该可以工作,并且它似乎与 ASP.NET 模型绑定非常相似(无论如何,在我看来).MyDocument 是一个 POCO,只有 3 个属性.

                Notice that MyDocument is the first parameter instead of HttpRequestMessage. I've read in the documentation that this approach should work, and it seems very similar to ASP.NET model binding (in my mind, anyway). MyDocument is a POCO with just 3 properties.

                public class MyDocument
                {
                    public string Name { get; set; }
                    public int ShoeSize { get; set; }
                    public decimal Balance { get; set; }
                }
                

                当我像这样 POST 到函数时(我正在使用 Postman):

                When I POST to the function like so (I'm using Postman):

                我收到一条错误消息:[8/8/2017 2:21:07 PM] 执行函数时出现异常:Functions.HttpTriggerCSharpSet.Microsoft.Azure.WebJobs.Host:异常绑定参数req".System.Net.Http.Formatting:没有 MediaTypeFormatter 可用于从内容中读取MyDocument"类型的对象(您也可以在上面的 Postman 屏幕截图中看到)

                I get an error message: [8/8/2017 2:21:07 PM] Exception while executing function: Functions.HttpTriggerCSharpSet. Microsoft.Azure.WebJobs.Host: Exception binding parameter 'req'. System.Net.Http.Formatting: No MediaTypeFormatter is available to read an object of type 'MyDocument' from content (which you can also see in the screenshot of Postman above)

                我已经尝试过来自 Postman 的 form-data 和 x-www-form-urlencoded,甚至是 raw,每次都出现同样的错误.我也尝试切换回 HttpRequestMessage 并使用 req.Content.ReadAsAsync<MyDocument>,我得到了类似的错误.我是在错误地构建我的 POST,还是我错误地编写了我的 Azure 函数.无论哪种情况,正确的方法是什么?

                I've tried form-data and x-www-form-urlencoded and even raw from Postman, same error every time. I've also tried switching back to HttpRequestMessage and using req.Content.ReadAsAsync<MyDocument>, and I get a similar error. Am I constructing my POST incorrectly, or am I writing my Azure Function incorrectly. In either case, what's the correct way?

                推荐答案

                一定要指定标题:

                Content-Type: application/json
                

                那么以下主体应该适用于您的代码:

                then the following body should work for your code:

                {
                    "Name": "myUserName",
                    "Balance": 123.0,
                    "ShoeSize": 30
                }
                

                这篇关于Azure Functions 模型绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Azure 函数静态隔离 下一篇:Azure Functions:队列触发器需要 Base-64 消息,但未正确处理它们

                相关文章

                <i id='tdpvC'><tr id='tdpvC'><dt id='tdpvC'><q id='tdpvC'><span id='tdpvC'><b id='tdpvC'><form id='tdpvC'><ins id='tdpvC'></ins><ul id='tdpvC'></ul><sub id='tdpvC'></sub></form><legend id='tdpvC'></legend><bdo id='tdpvC'><pre id='tdpvC'><center id='tdpvC'></center></pre></bdo></b><th id='tdpvC'></th></span></q></dt></tr></i><div id='tdpvC'><tfoot id='tdpvC'></tfoot><dl id='tdpvC'><fieldset id='tdpvC'></fieldset></dl></div>

                <tfoot id='tdpvC'></tfoot>
                1. <legend id='tdpvC'><style id='tdpvC'><dir id='tdpvC'><q id='tdpvC'></q></dir></style></legend>
                  • <bdo id='tdpvC'></bdo><ul id='tdpvC'></ul>

                    <small id='tdpvC'></small><noframes id='tdpvC'>