本文介绍了创建并请求azure参数函数数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我正在尝试创建一个Azure参数函数数组,但它对我不起作用。对于这些,我尝试下面的代码。 我尝试过: 使用系统; 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Text; 使用 System.Threading.Tasks; 命名空间 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功能 使用 System.Collections。通用; 使用 System.Net; 使用 System.Net.Http; 使用 Microsoft.Azure.WebJobs; 使用 Microsoft.Azure.WebJobs.Extensions.Http; 使用 Microsoft.Azure.WebJobs.Host; 命名空间 FunctionApp4 { public static class Function4 { [FunctionName( Function4)] public static HttpResponseMessage运行([HttpTrigger(AuthorizationLevel.Anonymous, get, post,Route = Function4 / {ALCBarCodes})] HttpRequestMessage req,List< ALCBarCodes> list,TraceWriter log) { log.Info( C#HTTP触发函数处理了一个请求。); // 从请求网址中的路径参数中获取名称 return req.CreateResponse(HttpStatusCode.OK,list); } } } 在这种情况下,如何申请网址? 我在URL下面尝试过但是没有用。 http:// localhost:7071 / api / Function4 / 1 对此有何帮助?解决方案 最后在代码下工作。 使用 System.Collections.Generic; 使用 System.Linq; 使用 System.Net; 使用 System.Net.Http; 使用 System.Threading.Tasks; 使用 Microsoft.Azure.WebJobs; 使用 Microsoft.Azure.WebJobs.Extensions.Http; 使用 Microsoft.Azure.WebJobs.Host; 使用 Newtonsoft.Json; 命名空间论坛 { public static class Function1 { [FunctionName( Function1)] public static async 任务< HttpResponseMessage>运行( [HttpTrigger(AuthorizationLevel.Anonymous, post,Route = null )] HttpRequestMessage req, TraceWriter log) { log.Info( C#HTTP触发函数处理了一个请求。); // dynamic input = await req.Content.ReadAsAsync< dynamic>(); ALCBarCodes [] input = await req.Content.ReadAsAsync< ALCBarCodes [] > (); // 从请求网址中的路径参数中获取名称 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 }, { BarCodeTex t: 1234, BarCodeWidth: 90, BarCodeHeight: 1234, BarCodeType: 128, BarCodeFont: 12 }, { BarCodeText: 1234, BarCodeWidth: 90, BarCodeHeight: 1234, BarCodeType: 128, BarCodeFont: 12 } ] I am trying to create an Array of Azure parameter function, but it's not working for me. For these, I tried below code.What I have tried: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 Functionusing 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); } }}On this case how can I request the URL?I tried below URL but it's not working.http://localhost:7071/api/Function4/1Any help on this? 解决方案 Finally worked below code.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; } }}Sample input:[{"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"}] 这篇关于创建并请求azure参数函数数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-21 19:25