public void CreateEvent(Guid eventId, string eventType = "DetailsView") { HttpStatusCode statusCode; string reasonPhrase; using (var client = HttpClient()) { var @event = new { EventId = eventId, Timestamp = DateTimeFactory.Now().ToString("O"), EventType = eventType }; var eventJson = JsonConvert.SerializeObject(@event, _jsonSettings); var requestContent = new StringContent(eventJson, Encoding.UTF8, "application/json"); var request = new HttpRequestMessage(HttpMethod.Post, "/events"); request.Content = requestContent; var response = client.SendAsync(request); var result = response.Result; statusCode = result.StatusCode; reasonPhrase = result.ReasonPhrase; request.Dispose(); response.Dispose(); result.Dispose(); } if (statusCode != HttpStatusCode.Created) { throw new InvalidOperationException(reasonPhrase); } }