Skip to content

Instantly share code, notes, and snippets.

@ajcronk
Created August 24, 2015 21:27
Show Gist options
  • Save ajcronk/955bcf48f0df26b51fa5 to your computer and use it in GitHub Desktop.
Save ajcronk/955bcf48f0df26b51fa5 to your computer and use it in GitHub Desktop.
public static bool sendAuthorizedHttpRequest(string server, string functionUrl, string command, string apiKey, string apiSecret, byte[] data)
{
try
{
using (var client = new System.Net.WebClient())
{
AddAuthroizationHeader(client, apiKey, apiSecret);
client.UploadData(server + functionUrl, command, data);
}
return true;
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
return false;
}
}
private static void AddAuthroizationHeader(WebClient client, string key, string secret)
{
var encodedCredentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(String.Format("{0}:{1}", key, secret)));
var authString = String.Format("Basic {0}", encodedCredentials);
client.Headers.Add(HttpRequestHeader.Authorization, authString);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment