Created
August 24, 2015 21:27
-
-
Save ajcronk/955bcf48f0df26b51fa5 to your computer and use it in GitHub Desktop.
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
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