Created
November 3, 2017 13:36
-
-
Save shturm/298203eb3a98063b7237c39b21a3ef00 to your computer and use it in GitHub Desktop.
c# post json
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
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