[csharp] HttpTrigger Function

Viewer

copydownloadembedprintName: HttpTrigger Function
  1.  public class ZiflowEventListener
  2.         {
  3.             [FunctionName("ZiflowEventListener")]
  4.             public static async Task<IActionResult> Run(
  5.                 [HttpTrigger(AuthorizationLevel.Anonymous"get""post", Route = null)] HttpRequest req, ILogger logger)
  6.             {
  7.                 string requestBody = string.Empty;
  8.                 try
  9.                 {
  10.                     requestBody = await new StreamReader(req.Body).ReadToEndAsync();
  11.                     if (!string.IsNullOrEmpty(requestBody))
  12.                     {
  13.                         string entryCode = req.Query["Key"];
  14.                         
  15.                         string token = req.Headers["x-ziflow-signature"];
  16.                         if (SignatureValidator.IsValid(token, requestBody))
  17.                         {
  18.                             await using var producerClient = new EventHubProducerClient("EVENTHUB-CONNECTIONSTRING""EVENTHUBNAME");
  19.                             using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
  20.     
  21.                             eventBatch.TryAdd(new EventData(Encoding.UTF8.GetBytes(requestBody)));
  22.                             await producerClient.SendAsync(eventBatch);
  23.                         }
  24.                         else
  25.                         {
  26.                             return new UnauthorizedResult();
  27.                         }
  28.                     }
  29.                 }
  30.                 catch (Exception ex)
  31.                 {
  32.                     logger.LogError($"AE_Exception:Exception : {ex.Message}");
  33.                     throw;
  34.                 }
  35.                 return new OkResult();
  36.             }
  37.         }

Editor

You can edit this paste and save as new:


File Description
  • HttpTrigger Function
  • Paste Code
  • 17 Jul-2022
  • 1.66 Kb
You can Share it: