Skip to content

Instantly share code, notes, and snippets.

@sdurandeu
Created September 5, 2014 15:53
Show Gist options
  • Save sdurandeu/a7b69c1a6b119c867106 to your computer and use it in GitHub Desktop.
Save sdurandeu/a7b69c1a6b119c867106 to your computer and use it in GitHub Desktop.
JSON Request with HttpClient
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