/// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param> /// <returns>Success</returns> /// <exception cref="ImperaPlusException">A server side error occurred.</exception> public async Task PostSendAsync(SendMessage message, CancellationToken cancellationToken) { var url_ = string.Format("{0}/{1}", BaseUrl, "api/messages"); var client_ = await CreateHttpClientAsync(cancellationToken).ConfigureAwait(false); var request_ = new HttpRequestMessage(); PrepareRequest(client_, ref url_); var content_ = new StringContent(JsonConvert.SerializeObject(message)); content_.Headers.ContentType.MediaType = "application/json"; request_.Content = content_; request_.Method = new HttpMethod("POST"); request_.RequestUri = new Uri(url_, UriKind.RelativeOrAbsolute); var response_ = await client_.SendAsync(request_, HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false); ProcessResponse(client_, response_); var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); var status_ = ((int)response_.StatusCode).ToString(); if (status_ == "200") { return; } else { } throw new ImperaPlusException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null); }
/// <returns>Success</returns> /// <exception cref="ImperaPlusException">A server side error occurred.</exception> public Task PostSendAsync(SendMessage message) { return PostSendAsync(message, CancellationToken.None); }