Skip to content

Instantly share code, notes, and snippets.

@ahelland
Created December 20, 2017 17:20
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ahelland/49e869ec27b75e9fa5d209970a2e347d to your computer and use it in GitHub Desktop.
Save ahelland/49e869ec27b75e9fa5d209970a2e347d to your computer and use it in GitHub Desktop.
Azure Function for making an http request to an API behind Azure API Management
using System;
using System.Text;
using System.Net.Http;
using System.Net.Http.Headers;
public static void Run(string input, TraceWriter log)
{
log.Info($"C# manually triggered function called with input: {input}");
var apimUrl = " https://contosio.azure-api.net/foo/messages";
var content = "{\"on\":true, \"sat\":254, \"bri\":254, \"hue\":10000}";
var AADToken = "token";
HttpClient Client = new HttpClient();
Client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", AADToken);
Client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key","subKey");
var foo = Client.PostAsync(apimUrl, new StringContent(content.ToString())).Result;
log.Info($"result: {foo}");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment