protected async Task <RPCResponse> SendAsync(RPCRequest request) { var httpClient = GetOrCreateHttpClient(); var httpContent = new StringContent(request.Parameters.ToString(), Encoding.UTF8, "application/json"); httpContent.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var cancellationTokenSource = new CancellationTokenSource(); cancellationTokenSource.CancelAfter(ConnectionTimeout); var httpResponseMessage = await httpClient.PostAsync(request.Route, httpContent, cancellationTokenSource.Token).ConfigureAwait(false); httpResponseMessage.EnsureSuccessStatusCode(); var stream = await httpResponseMessage.Content.ReadAsStreamAsync(); using (var streamReader = new StreamReader(stream)) using (var reader = new JsonTextReader(streamReader)) { var serializer = JsonSerializer.Create(_jsonSerializerSettings); var message = serializer.Deserialize <RPCResponse>(reader); return(message); } }
public async Task <T> SendRequestAsync <T>(RPCRequest request) { var response = await SendAsync(request); return(response.GetData <T>()); }