Skip to content

Instantly share code, notes, and snippets.

@ThomasPe
Created January 6, 2018 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasPe/7389654450c5e30460e44508b395cc1f to your computer and use it in GitHub Desktop.
Save ThomasPe/7389654450c5e30460e44508b395cc1f to your computer and use it in GitHub Desktop.
A C# Azure Function for calling webhooks with basic authentication
using System;
using System.Net;
[FunctionName("GetEnvironmentVariables")]
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 = "https://mywebhookurl.com";
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();
log.Info(response.ToString());
}
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