Created
December 20, 2017 17:20
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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