Skip to content

Instantly share code, notes, and snippets.

@justintoth
Created February 25, 2013 02:53
Show Gist options
  • Save justintoth/5027122 to your computer and use it in GitHub Desktop.
Save justintoth/5027122 to your computer and use it in GitHub Desktop.
public static string PostWithAuth(string url, string requestBody = null, string method = "POST") {
using (WebClient client = new WebClient()) {
var credentials = Convert.ToBase64String(Encoding.Default.GetBytes(APIKey));
client.Headers.Add(HttpRequestHeader.Authorization, credentials);
client.Headers.Add(HttpRequestHeader.ContentType, "application/json");//x-www-form-urlencoded
if (!String.IsNullOrEmpty(requestBody))
return client.UploadString(url, method, requestBody);
else
return client.UploadString(url, method);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment