c# - 创建和请求 Azure 参数函数数组

标签 c# azure azure-functions

我正在尝试创建一个 Azure 参数函数数组,但它对我不起作用。对于这些,我尝试了下面的代码。

ABCBarCodes 类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace FunctionApp4
{

    public class ALCBarCodes
    {

        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }

    }

}

Azure 函数

using System.Collections.Generic;
using System.Net;
using System.Net.Http;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;

namespace FunctionApp4
{
    public static class Function4
    {
        [FunctionName("Function4")]
        public static HttpResponseMessage Run([HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = "Function4/{ALCBarCodes}")]HttpRequestMessage req, List<ALCBarCodes> list, TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

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

在这种情况下我如何请求 URL?

我尝试了以下网址,但不起作用。

http://localhost:7071/api/Function4/1

对此有什么帮助吗?

最佳答案

这是工件。请尝试这个

using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading.Tasks;
using Microsoft.Azure.WebJobs;
using Microsoft.Azure.WebJobs.Extensions.Http;
using Microsoft.Azure.WebJobs.Host;
using Newtonsoft.Json;

namespace Forum
{
    public static class Function1
    {
        [FunctionName("Function1")]
        public static async Task<HttpResponseMessage> Run(
            [HttpTrigger(AuthorizationLevel.Anonymous, "post", Route = null)]
            HttpRequestMessage req,
            TraceWriter log)
        {
            log.Info("C# HTTP trigger function processed a request.");

            //dynamic input =await req.Content.ReadAsAsync<dynamic>();

            ALCBarCodes[] input = await req.Content.ReadAsAsync<ALCBarCodes[]>();

            // Fetching the name from the path parameter in the request URL
            return req.CreateResponse(HttpStatusCode.OK, input);
        }
    }
    public class ALCBarCodes
    {
        public string BarCodeText { get; set; }
        public string BarCodeWidth { get; set; }
        public string BarCodeHeight { get; set; }
        public string BarCodeType { get; set; }
        public string BarCodeFont { get; set; }
    }
}

示例输入:

[
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
},
{
"BarCodeText": "1234",
"BarCodeWidth": "90",
"BarCodeHeight": "1234",
"BarCodeType": "128",
"BarCodeFont": "12"
}
]

关于c# - 创建和请求 Azure 参数函数数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55121783/

相关文章:

azure - Azure AD B2C 上的自定义属性为 stringCollection

azure - 当 Azure 上的 SQL 数据库发生故障时,哪个配置逻辑信号将用于 SQL 数据库的警报规则?

javascript - Azure Functions [JavaScript/Node.js] - HTTP 调用,良好实践

c# - 模拟只读索引器属性

c# - 以 Windows 服务用户身份运行进程失败并拒绝访问?

c# - 删除按钮边框窗体

javascript - 在 asp.net 中,Ajax 返回数据表总是出现错误部分

azure - Azure Web 应用程序中 BouncyCaSTLe 的 DecryptKey 方法失败

python-3.x - Azure Function-使用 python 代码解压缩受密码保护的文件

Azure Function - 时间触发函数状态