public static async Task stringPostStreamAsync(RateHistoryRequestBase content, CancellationToken token, IProgress <string> rateResponse) { using (var request = new HttpRequestMessage(HttpMethod.Post, content.providerUrl)) using (var httpContent = CreateHttpContent(content)) { request.Content = httpContent; using (var response = await httpClient .SendAsync(request, HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { while (!token.IsCancellationRequested) { string jsonResponse = await response.Content.ReadAsStringAsync(); rateResponse.Report(jsonResponse); await Task.Delay(Properties.Settings.Default.UpdateDelaySetting); } throw new TaskCanceledException(); } } } }
public static async Task <string> PostStreamAsync(RateHistoryRequestBase content) { using (var request = new HttpRequestMessage(HttpMethod.Post, content.providerUrl)) using (var httpContent = CreateHttpContent(content)) { request.Content = httpContent; using (var response = await httpClient .SendAsync(request, HttpCompletionOption.ResponseHeadersRead) .ConfigureAwait(false)) { if (response.IsSuccessStatusCode) { string jsonResponse = await response.Content.ReadAsStringAsync(); return(jsonResponse); } else { return(string.Empty); } } } }