Перейти к основному контенту

Get response from PostAsJsonAsync

var httpClient = new HttpClient()

var task = httpClient.PostAsJsonAsync(posturi, model)
	.ContinueWith( x => x.Result.Content.ReadAsAsync<bool>().Result);

// 1. GETTING RESPONSE - NOT ASYNC WAY
task.Wait(); //THIS WILL HOLD THE THREAD AND IT WON'T BE ASYNC ANYMORE!
bool response = task.Result

// 2. GETTING RESPONSE - TASK ASYNC WAY (usually used in < .NET 4.5 
task.ContinueWith( x => {
	bool response = x.Result
});

// 3. GETTING RESPONSE - TASK ASYNC WAY (usually used in >= .NET 4.5 
bool response = await task;