我正在尝试创建一个 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/