Created
September 5, 2014 15:53
-
-
Save sdurandeu/a7b69c1a6b119c867106 to your computer and use it in GitHub Desktop.
JSON Request with HttpClient
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
var operationUrl = string.Format("{0}/repos/{1}/{2}/commits/{3}/comments", GitHubClientApiUrl, this.repoOwner, this.repoName, commitId); | |
var jsonBody = JsonConvert.SerializeObject(new { body = message }); | |
using (var httpClient = new HttpClient()) | |
{ | |
httpClient.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Token", ConfigurationManager.AppSettings["GitHubApiAccessToken"]); | |
httpClient.DefaultRequestHeaders.Add("User-Agent", UserAgent); | |
httpClient.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); | |
return await httpClient.PostAsync(new Uri(operationUrl), new StringContent(jsonBody)); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment