Skip to content

Instantly share code, notes, and snippets.

@shturm
Created November 3, 2017 13:36
Show Gist options
  • Save shturm/298203eb3a98063b7237c39b21a3ef00 to your computer and use it in GitHub Desktop.
Save shturm/298203eb3a98063b7237c39b21a3ef00 to your computer and use it in GitHub Desktop.
c# post json
protected async Task UploadPost(Post post, string endpoint)
{
var client = new HttpClient();
var json = JsonConvert.SerializeObject(post, Formatting.Indented);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var url = $"{endpoint}";
var response = await client.PostAsync(url, content);
if (!response.IsSuccessStatusCode)
{
throw new Exception($"Could not upload post {post.DetailsUri}: {response.ReasonPhrase}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment