Created
February 27, 2013 03:11
-
-
Save justintoth/5044664 to your computer and use it in GitHub Desktop.
This file contains 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 string PostWithAuth(string url, string requestBody = null, string method = "POST") { | |
using (WebClient client = new WebClient()) { | |
var credentials = "Basic " + Convert.ToBase64String(Encoding.UTF8.GetBytes(APIKey + ":")); | |
client.Headers.Add(HttpRequestHeader.Authorization, credentials); | |
client.Headers.Add(HttpRequestHeader.Accept, "application/json"); | |
client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); | |
client.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; .NET CLR 1.0.3705;)"); | |
return client.UploadString(url, method, !String.IsNullOrEmpty(requestBody) ? requestBody : "{}"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment