Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A C# Azure Function for calling webhooks with basic authentication
using System;
using System.Net;
public static void Run(TimerInfo myTimer, TraceWriter log)
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
string username = GetEnvironmentVariable("Webhook_Username");
string password = GetEnvironmentVariable("Webhook_Password");
string webhook = "";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(webhook);
string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(username + ":" + password));
req.Headers.Add("Authorization", "Basic " + encoded);
req.Method = "POST";
req.ContentLength = 0;
var response = req.GetResponse();
public static string GetEnvironmentVariable(string name)
return System.Environment.GetEnvironmentVariable(name, EnvironmentVariableTarget.Process);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment